2016-06-21 8 views
0

EDIT:私の機能を更新しました! 私はsap.ui.tableにJSONデータをバインドしたいが、私はちょっとだからこれは私のテーブルで、これはJSONをテーブルにバインドする

をどのように動作するか見当もつかない:

<content> 
<t:Table id="transactionUiTable" 
       columnHeaderVisible="true" 
       selectionMode="Single" 
       selectionBehavior="RowSelector" 
       enableColumnReordering="false" 
       enableGrouping="false" 
       showColumnVisibilityMenu="false" 
       enableSelectAll="false" 
       enableCustomFilter="false" 
       enableBusyIndicator="false" 
       rows="{path: '/'}" 
       rowSelectionChange="onTableSelectionChange"> 
        <t:toolbar> 
         <Toolbar id="toolbar"> 
           <Input width="15%" id="transactionId" value="txn_18KlBw2eZvKYlo2CdHGDlpAJ"/> 
           <Button text="Search Transaction" type="Emphasized" icon="sap-icon://search" press="onTransactionByTransactionId"/> 
           <Button text="Transactionlist" type="Unstyled" press="onTransactionList"/> 
           <Button text="Customer Transactionlist" type="Unstyled" press="onCustomerTransactionList"/> 
           <ToolbarSpacer/> 
           <Button icon="sap-icon://action-settings" type="Default" /> 
         </Toolbar> 
        </t:toolbar> 
        <t:columns> 
         <t:Column id="id" hAlign="Center" width="10%"> 
          <Label id="labelId" text="Transaction Id"></Label> 
          <t:template> 
           <Text text="{orderId}"/> 
          </t:template> 
         </t:Column> 
         <t:Column id="columnDate" hAlign="Center"> 
          <Label id="labelDate" text="Date"></Label> 
         </t:Column> 
         <t:Column id="columnAmount" hAlign="Center"> 
          <Label id="labelAmount" text="Amount"></Label> 
         </t:Column> 
         <t:Column id="columnCurrency" hAlign="Center"> 
          <Label id="labelCurrency" text="Currency"></Label> 
         </t:Column> 
         <t:Column id="columnFee" hAlign="Center"> 
          <Label id="labelFee" text="Fee"></Label> 
         </t:Column> 
         <t:Column id="columnNet" hAlign="Center"> 
          <Label id="labelNet" text="Net"></Label> 
         </t:Column> 
         <t:Column id="columnType" hAlign="Center"> 
          <Label id="labelType" text="Type"></Label> 
         </t:Column> 
          <t:Column id="columnStatus" hAlign="Center"> 
          <Label id="labelStatus" text="Status"></Label> 
         </t:Column> 
        </t:columns> 
       </t:Table> 
      </content> 

テキストとボタンをクリックして "検索トランザクション」、私はすでに値でそれを満たし、入力フィールドに書いたことができるのtransactionId、とサービスにGET経由で呼び出したい 『txn_blablabla』

ので、これは私の関数である:

onTransactionByTransactionId : function() { 
     this.oView = this.getView(); 
     var query = this.oView.byId("transactionId").getValue(); 

     var oJsonModel = new sap.ui.model.json.JSONModel(); 
     oJsonModel.loadData("/retrieveTransacion?transactionId=" + query , {}, false); 

     var oData = oJsonModel.getProperty("/"); 
     this.oView.setModel(oData); 


    } 

変数oDataにバインドされたJSONを取得しましたが、JSONデータをテーブルの列にバインドするにはどうすればよいですか?私はIDが「columnAmount」とコラムでJSONデータ量をバインドしたい例えば

....

答えて

1

あなたはほとんどが実際にしています。あなたがする必要がある唯一のことはすなわち、JSONModelにではなく、生のJSONデータにモデルを設定することです:

this.oView.setModel(oData); - >this.oView.setModel(oJsonModel);

また、あなたのJSONModelの初期化を移動すると結合しますinitセクションのビューに移動します。これは、検索ボタンを押すたびに実行する必要はないためです。これをinitメソッドに移すことで、コードの実行速度が向上し、より理解しやすくなると思います。

(それが公共countrylistサービスに接続できるように)このjsbinわずかにきれいにし、修正版を見つけてください:本当に私の問題で私を助けhttp://jsbin.com/laqefak/1/edit?html,output

+0

感謝の伴侶を、どうもありがとうございました:) – ECasio

+0

1私の場合、このJSONデータを取得します。{JSON DATA} JSONデータに見つからない括弧のように思えますバインディングが機能していないために問題が発生しました。最初にそのJSONデータを配列に変換する必要がありますか? – ECasio

+0

[]内は、配列を扱っていることを意味します。 {}はオブジェクトであり、配列の一部にすることができます。テーブルの行(項目)などの集約をバインドする場合は、配列にバインドする必要があります。バインドしたい配列がその{}オブジェクトの一部になっている可能性がありますか? {製品:[{id:product1}、{id:product2}]}?その場合、/の代わりに/ Productsにバインドする必要があります。 – jpenninkhof

関連する問題