【问题标题】:SAPUI5 - MVC CRUD Table No dataSAPUI5 - MVC CRUD 表无数据
【发布时间】:2014-07-10 16:08:09
【问题描述】:

创建了一个 sapui5 MVC CRUD 应用程序,我需要你的帮助。

  1. 为什么视图中没有数据?
  2. 是绑定问题吗?
  3. 我的 CRUD.view.xml 是否正确?
  4. 如何在单独的文件中调用 JSON 数据? sap.ui.resource() 或 jQuery.sap.getModulePath()
  5. 有哪些解决方案?

CRUD.controller.js onInit 函数

  onInit: function () {

    // JSON data normally on a seperate file
    var oData = {
            ApplicationCollection : [
        {
          "applicationId" : "0001",
          "name" : "John Doe",
          "connectionPath" : "index.html",
          "imagePath" : "Image Path",
          "subApplicationId": "Sub ID",
          "status": "active"
        },
        {
          "applicationId" : "0002",
          "name" : "Jane Doe",
          "connectionPath" : "index.html",
          "imagePath" : "Image Path",
          "subApplicationId": "Sub ID",
          "status": "active"
        },
        {
          "applicationId" : "0003",
          "name" : "Mary Jane",
          "connectionPath" : "index.html",
          "imagePath" : "Image Path",
          "subApplicationId": "Sub ID",
          "status": "active"
        },
        {
          "applicationId" : "0004",
          "name" : "Bob Foo",
          "connectionPath" : "index.html",
          "imagePath" : "Image Path",
          "subApplicationId": "Sub ID",
          "status": "active"
        }
      ]
    };

    var oModel = new sap.ui.model.json.JSONModel();
    oModel.setData(oData);
    this.getView().setModel(oModel);
  }

CRUD.view.xml

<mvc:View
   controllerName="sap.ui.crud.view.CRUD"
   xmlns:mvc="sap.ui.core.mvc"
   xmlns="sap.m">
    <Table
      id="idProductsTable"
      inset="false"
      items="{
        path: '/ApplicationCollection'      
      }">
     <headerToolbar>
       ...
     </headerToolbar>
     <columns> <!-- Columns Header -->
       ...
     </columns> <!-- End of Columns Header -->
     <items> <!-- Column List -->
       <ColumnListItem>
        <cells>
          <Text
            text="{applicationId}" />
          <Text
            text="{name}" />
          <Text
            text="{connectionPath}" />
          <Text
            text="{imagePath}" />
          <Text
            text="{subApplicationId}" />  
          <Text 
            text="{status}" />            
        </cells>
      </ColumnListItem>
     </items> <!-- End of Column List -->
   </Table>

</mvc:View>

【问题讨论】:

    标签: sapui5


    【解决方案1】:
    1. 只需使用&lt;Table ... items="{/ApplicationCollection}"&gt;... 就可以了
    2. 不一定,只是语法错误;-)
    3. 是的,应该可以正常工作!
    4. 为什么不使用

      var oAnotherModel = new sap.ui.model.json.JSONModel("resources/your_other.json");
      this.getView().setModel(oAnotherModel);
      

    我不完全确定你所说的 5) 是什么意思,你能详细说明一下吗?

    编辑:在此处查看您的代码:http://jsbin.com/biyiq/1/edit

    【讨论】:

    • 1.没有工作仍然没有数据。 4. 试了一下,出现解析错误 我需要在 Component.js 中为 JSON 数据配置一些东西吗?
    • 1.请参阅上面的更新答案,那么您的代码中肯定还有其他问题。 4. 不,应该按预期工作。你的 JSON 文件有效吗?
    • 第一季度。我让它在 JS 视图版本中工作,但不是在 XML 中。是的,我将其更改为{/ApplicatonCollection}。 Q4。我确定它是有效的。嗯,也许我会再试一次或尝试清除我的浏览数据。
    • 奇怪...你看到我的代码和你的代码在绑定方面有什么不同吗?
    猜你喜欢
    • 2016-03-22
    • 1970-01-01
    • 2016-10-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多