2014-11-02 50 views
0

我創建的XML視圖和控制器將數據綁定。 我沒有看到任何數據。 我錯過了什麼嗎?結合不工作於表sapui5

<sap.ui.core.mvc:View controllerName="view.weeklyTasks" 
    xmlns="sap.m" 
    xmlns:sap.ui.core="sap.ui.core" 
    xmlns:sap.ui.core.mvc="sap.ui.core.mvc"> 
    <Page title="Title"> 
    <content> 
     <Table id="idProductsTable" noDataText="No data" items="{path: '/modelData'}" > 
     <columns> 
      <Column> 
      <Text text="Product" /> 
      </Column> 
      <Column> 
      <Text text="Supplier" /> 
      </Column> 
     </columns> 
     <items> 
      <ColumnListItem counter="0"> 
      <cells> 
       <Text text="{name}"></Text> 
       <Text text="{date}"></Text> 
      </cells> 
      </ColumnListItem> 
     </items> 
     <headerToolbar> 
      <Toolbar> 
      <content> 
       <Label text="Weekly Tasks"></Label> 
      </content> 
      </Toolbar> 
     </headerToolbar> 
     </Table> 
    </content> 
    </Page> 
</sap.ui.core.mvc:View> 

sap.ui.controller("view.weeklyTasks", { 
    onInit: function() { 

    var aData = { modelData : [ 
     {name: "Peter", date: "01012010"}, 
     {name: "Petra", date: "01012011"}, 
     {name: "Thomas", date: "01012012"}, 
     {name: "John", date: "01012013"}, 
     {name: "Maria", date: "01012014"} 
    ]}; 



    var oModel = new sap.ui.model.json.JSONModel(aData); 
    this.getView().setModel(oModel); 
    } 
}); 
+0

我試圖重現你的代碼,但我還找不到完整的解決方案。但是,我可以看到您的JSON無效。你必須在「modelData」,「name」和「date」中加雙引號。 您可以使用以下鏈接來驗證JSON http://jsonformatter.curiousconcept.com/# – fabiopagoti 2014-11-02 22:10:41

回答

3

好吧,現在我可以使事情工作。

1 - 下面添加的參數,以此來bootstap

data-sap-ui-xx-bindingSyntax="complex" 

有關數據SAP-UI-XX綁定語法更多信息:

Data Modeling for controls using XML views(SAPUI5)

SAP Help - SAPUI5 Configuration Options

2 - 你的看法OK

<Page title="Title"> 
    <content> 
    <Table id="idProductsTable" noDataText="No data" items="{path: '/modelData'}" > 
     <columns> 
     <Column> 
      <Text text="Product" /> 
     </Column> 

     <Column> 
      <Text text="Supplier" /> 
     </Column> 
     </columns> 

     <items> 
     <ColumnListItem > 
      <cells>  
      <Text text="{name}"></Text> 
      <Text text="{date}"></Text> 
      </cells> 
     </ColumnListItem> 
     </items> 
    </Table> 
    </content> 
</Page> 

3 - 更新您的控制器固定JSON格式

onInit: function() { 

    var aData = { "modelData" : [ 

    {"name": "Peter", "date": "01012010"}, 
    {"name": "Petra", "date": "01012011"}, 
    {"name": "Thomas", "date": "01012012"}, 
    {"name": "John", "date": "01012013"}, 
    {"name": "Maria", "date": "01012014"} 
    ]}; 

    var oModel = new sap.ui.model.json.JSONModel(aData); 

    this.getView().setModel(oModel); 
    // OR sap.ui.getCore().setModel(oModel); 
} 
+0

'data-sap-ui-xx-bindingSyntax =「complex」'是我所缺少的。現在工作。謝謝 – 2017-04-19 10:14:21

0

我期待的項目屬性綁定到控制器,因此它可以動態改變,我怎麼會去這樣做?

我想這將是如果硬編碼像oTable.items = "{odataURL}"

我的URL現在的作品,但我不知道我怎麼能得到相同的結果在controller.js這樣

0
As per Question asked there is no need to make change in JSON format . 
Normally we use Complex Binding when we have formatter/sorter or path added 
we can achieve above result in other way also 
just remove **path** from item and remove **data-sap-ui-xx-bindingSyntax="complex"** in  index.html 

<Table id="idProductsTable" noDataText="No data" items="{/modelData}"> 
     <columns> 
     <Column> 
      <Text text="Product" /> 
     </Column> 

     <Column> 
      <Text text="Supplier" /> 
     </Column> 
     </columns> 

     <items> 
     <ColumnListItem > 
      <cells>  
      <Text text="{name}"></Text> 
      <Text text="{date}"></Text> 
      </cells> 
     </ColumnListItem> 
     </items> 
    </Table>