简体   繁体   English

从对象数组进行UI5数据绑定(JS视图)

[英]UI5 Data Binding from an Array of Objects (JS View)

I am trying to bind Data to my table . 我试图将数据绑定到我的表。

My Data looks like this : 我的数据如下所示: 在此处输入图片说明

And relevant parts of my Code : 和我的代码的相关部分:

from View : 从视图:

var innerTable2 = new sap.m.Table(this.createId("innerTable2"), {
        columns: [
            new sap.m.Column({
                header: new sap.m.Label({
                    text: " Header Text"
                })
            }),
            new sap.m.Column({
                header: new sap.m.Label({
                    text: " Header Text 2"
                })
            })
        ]
    }).addStyleClass("table-result");

from Controller : 来自控制器:

// creating path for the property I need
var path_STOFFTYP = "{" + elementId + "/stoff/STOFFTYP}";
var oInnerTemplate2 = new sap.m.ColumnListItem({
    cells: [
        new sap.m.Text({
            text: "test"
        }),
        new sap.m.Text({
            text: path_STOFFTYP
        })
    ]
});
//here binding template to table 
this.byId("innerTable2").setModel(oModel).bindItems("/results/rs999", oInnerTemplate2);

If I leave the path_STOFFTYP as it is now, I don't recieve any data. 如果我保留path_STOFFTYP ,则不会接收任何数据。

If I make it only "stoff" it shows [object Object] as much as the length of stoff array. 如果我仅将其设置为“ stoff”,则它显示的[object Object]等于stoff数组的长度。

What I know, for sure is , the property "stoff" has at least 1 and maximum 65 different elements ( depends to the selected item. its dynamic) 我知道,可以肯定的是,属性“ stoff”至少具有1个,最多65个不同的元素(取决于所选项目。其动态)

If I change the var path_STOFFTYP to "{" + elementId + "/stoff/0/STOFFTYP}"; 如果我将var path_STOFFTYP更改为"{" + elementId + "/stoff/0/STOFFTYP}";

It shows the value of "Wirkstoff". 它显示“ Wirkstoff”的值。 Which is correct, however I don't want to create 60 different properties. 正确,但是我不想创建60个不同的属性。

My Question : How can I manage to get all values of the property "STOFFTYP" from the array "stoff" ? 我的问题:如何从数组“ stoff”中获取属性“ STOFFTYP”的所有值? I want to bind it dynamically. 我想动态绑定它。

I'm not sure if I understand exactly what you are trying to do. 我不确定我是否完全了解您要做什么。

But your Binding is wrong stoff is an array inside the results/rs999 array. 但是您的Binding错误是stoff是results / rs999数组中的一个数组。 So it is array in array. 所以它是数组中的数组。

Your template should only use relative bindings so 您的模板应仅使用相对绑定,因此

path_STOFFTYP = "{STOFFTYP}";

And then you should bind your items dynamically to some kind of this path: 然后,您应该将项目动态绑定到这种路径:

/here binding template to table 
this.byId("innerTable2").setModel(oModel).bindItems("/results/rs999/"+elementId+"/stoff", oInnerTemplate2);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM