【问题标题】:Setting data to JSON model, and then setting that model to a table in SAPUI5将数据设置为 JSON 模型,然后将该模型设置为 SAPUI5 中的表
【发布时间】:2015-08-12 10:18:15
【问题描述】:

这是我的 JSON 对象(在 JSONlint.com 验证):

[
    {
        "team": "xxx",
        "fname": "0",
        "lname": "C5042439"
    },
    {
        "team": "yyy",
        "fname": "0",
        "lname": "C5067631"
    }
]

我遵循了这个教程:http://scn.sap.com/docs/DOC-46156

在我的模型中,我最终拥有:

 var oTable = new sap.ui.table.Table({
    title: "Employee Details",                                   // Displayed as the heading of the table
    visibleRowCount: 3,                                           // How much rows you want to display in the table
    selectionMode: sap.ui.table.SelectionMode.Single, //Use Singe or Multi
    navigationMode: sap.ui.table.NavigationMode.Paginator, //Paginator or Scrollbar
    fixedColumnCount: 3,                     // Freezes the number of columns
    enableColumnReordering:true,       // Allows you to drag and drop the column and reorder the position of the column
    width:"1024px"                              // width of the table
  });

// Use the Object defined for table to add new column into the table
    oTable.addColumn({
    label: new sap.ui.commons.Label({text: "Team"}),             // Creates an Header with value defined for the text attribute
    template: new sap.ui.commons.TextField().bindProperty("value", "team"), // binds the value into the text field defined using JSON
    sortProperty: "team",        // enables sorting on the column
    filterProperty: "team",       // enables set filter on the column
    width: "125px"                  // width of the column
});

    oTable.addColumn({
    label: new sap.ui.commons.Label({text: "FName"}),
    template: new sap.ui.commons.TextField().bindProperty("value", "fname"),
    sortProperty: "fname",
    filterProperty: "fname",
    width: "125px"
});

    oTable.addColumn({
    label: new sap.ui.commons.Label({text: "Lname"}),
    template: new sap.ui.commons.Link().bindProperty("text", "lname"),
    sortProperty: "lname",
    filterProperty: "lname",
    width: "200px"
});

var vData =     
    [
        {
            "team": "xxx",
            "fname": "0",
            "lname": "C5042439"
        },
        {
            "team": "yyy",
            "fname": "0",
            "lname": "C5067631"
        }
    ];
 var oModel = new sap.ui.model.json.JSONModel();        // created a JSON model      
     oModel.setData({modelData: vData});                              // Set the data to the model using the JSON object defined already
     oTable.setModel(oModel);                                                                                  
     oTable.bindRows("/modelData");                              // binding all the rows into the model
     //Initially sort the table
     oTable.sort(oTable.getColumns()[0]);                
     oTable.placeAt("table");

我的问题是如何将该 JSON 模型绑定到表中,以便在模型中显示数据?目前我收到此错误: 未捕获的错误:“[object Object]”对于 Element sap.ui.table.Table#__table0 的聚合“列”无效

据我了解,将列绑定到实际数据有问题,但我不确定。任何帮助将不胜感激。

【问题讨论】:

    标签: json binding model sapui5


    【解决方案1】:

    您实际上是在向表中添加一个对象而不是列——oTable.addColumn() 需要一个 sap.ui.table.Column 类型的对象

    将您的代码更改为:

    oTable.addColumn(new sap.ui.table.Column({
        label: new sap.ui.commons.Label({text: "Lname"}),
        template: new sap.ui.commons.Link().bindProperty("text", "lname"),
        sortProperty: "lname",
        filterProperty: "lname",
        width: "200px"
    }));
    

    等等

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-06-25
      • 1970-01-01
      • 2015-11-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-10-10
      • 1970-01-01
      相关资源
      最近更新 更多