gpt4 book ai didi

sapui5 - openui5 : How to get current JSON model element in RowRepeater

转载 作者:行者123 更新时间:2023-12-04 17:13:13 25 4
gpt4 key购买 nike

我无法获取绑定(bind)到 RowRepeater 元素的当前 JSON 模型元素。
对于表格和列表,我只需检索当前索引(或多个索引),并根据这些值,指向我的 JSON 模型中的匹配元素。

但是,RowRepeater 元素没有当前索引属性。我觉得我应该能够直接检索当前元素,而不是通过当前索引间接检索,是否有更好、统一的方式来检索当前元素?

模型示例代码:

    var mydata = {
"data": [
{
"key": "67b895bf-8d89-11e3-94a7-0000005341de",
"name": "my 1st item"
},
{
"key": "7780de05-8d83-11e3-bec4-0000005341de",
"name": "my 2nd item"
}
]
};
var oModel = new sap.ui.model.json.JSONModel();
oModel.setData(dummydata);
sap.ui.getCore().setModel(oModel);

RowRepeater 的示例代码(我想在按下删除图标时检索当前的“键”):
    var oRowRepeater = new sap.ui.commons.RowRepeater();

//create the template control that will be repeated and will display the data
var oRowTemplate = new sap.ui.commons.layout.MatrixLayout();

var matrixRow, matrixCell, control;

// main row
matrixRow = new sap.ui.commons.layout.MatrixLayoutRow();

//Text
control = new sap.ui.commons.TextView();
control.bindProperty("text","name");

//add content to cell, cell to row
matrixCell = new sap.ui.commons.layout.MatrixLayoutCell();
matrixCell.addContent(control);
matrixRow.addCell(matrixCell);

//delete icon
var icon = new sap.ui.core.Icon({
src: sap.ui.core.IconPool.getIconURI("delete"),
size: "16px",
color: "#333",
activeColor: "#BBB",
hoverColor: "#888",
width: "60px",
});
icon.attachPress(function(oEvent) {
sap.ui.commons.MessageBox.alert("TODO: Implement delete based on current/data/?/key");
});

//add content to cell, cell to row
matrixCell = new sap.ui.commons.layout.MatrixLayoutCell({ hAlign : sap.ui.commons.layout.HAlign.Right });
matrixCell.addContent(icon);
matrixRow.addCell(matrixCell);

// add row to matrix
oRowTemplate.addRow(matrixRow);

//attach data to the RowRepeater
oRowRepeater.bindRows("/data", oRowTemplate);

最佳答案

以下对我有用

icon.attachPress(function(oEvent) {
sap.ui.commons.MessageBox.alert(this.getBindingContext().getProperty('name'));
});

选定的对象
var seletedRow = this.getBindingContext().getObject()

关于sapui5 - openui5 : How to get current JSON model element in RowRepeater,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21599459/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com