我尝试在动态表中创建动态combobox
或multiInput
。您可以在我期望的查看屏幕和我自己的代码下面看到。
onCreateTable: function () {
var summaryDetailData = {
"subvariants": [{
"kontrolNesnesiTanim": "test 1 Tanım",
"kontrolNesnesiBelirtim": "test 1 Belirtim",
"type": "comboBox",
"kontrolSonucu": {
"test0": "test00",
"test1": "test10",
"test2": "test20"
},
"kontrolEdilecek": 20,
"kontrolEdilen": 0,
"icon": "sap-icon://accept"
}, {
"kontrolNesnesiTanim": "test 2 Tanım",
"kontrolNesnesiBelirtim": "test 2 Belirtim",
"type": "input",
"kontrolSonucu": {
"test0": "test00",
"test1": "test10",
"test2": "test20",
"test3": "test30"
},
"kontrolEdilecek": 10,
"kontrolEdilen": 0,
"icon": "sap-icon://decline"
} ]
};
var oTable = new sap.m.Table("idRandomDataTable", {
headerToolbar: new sap.m.Toolbar({
content: [new sap.m.Label({
text: ""
})]
}),
columns: [new sap.m.Column({
width: "2em",
header: new sap.m.Label({
text: "Kontrol Nesnesi"
})
}), new sap.m.Column({
width: "2em",
header: new sap.m.Label({
text: "Kontrol Sonucu"
})
}), new sap.m.Column({
width: "2em",
header: new sap.m.Label({
text: "Kontrol Edilecek"
})
})]
});
this.getView().byId("SimpleFormChange480_TrialSonuc").addContent(oTable);
oTable.bindItems("/subvariants", new sap.m.ColumnListItem({
cells: [new sap.m.ObjectIdentifier({
title: "{kontrolNesnesiTanim}",
"titleActive": true,
text: "{kontrolNesnesiBelirtim}"
}),
this.kontrolSonucu("{type}"),
new sap.m.Input({
value: "{kontrolEdilen}"
})
]
}));
oTable.setModel(new sap.ui.model.json.JSONModel(summaryDetailData));
},
kontrolSonucu: function (type) {
if (type === "input") {
return new sap.m.MultiInput({
showValueHelp: false
});
} else {
return new sap.m.ComboBox({
items: {
path: "kontrolSonucu/",
template: new sap.ui.core.Item({
key: "{}",
change: "onChange",
text: "{}"
})
}
});
}
}
如何获取JSON作为函数参数?
我也想使用sap.m.table
库而不是sap.ui.table
期待您的回复。
答案 0 :(得分:0)
您可以使用 工厂功能
onCreateTable: function () {
var summaryDetailData = {
"subvariants": [{
"kontrolNesnesiTanim": "test 1 Tanım",
"kontrolNesnesiBelirtim": "test 1 Belirtim",
"type": "comboBox",
"kontrolSonucu": {
"test0": "test00",
"test1": "test10",
"test2": "test20"
},
"kontrolEdilecek": 20,
"kontrolEdilen": 0,
"icon": "sap-icon://accept"
}, {
"kontrolNesnesiTanim": "test 2 Tanım",
"kontrolNesnesiBelirtim": "test 2 Belirtim",
"type": "input",
"kontrolSonucu": {
"test0": "test00",
"test1": "test10",
"test2": "test20",
"test3": "test30"
},
"kontrolEdilecek": 10,
"kontrolEdilen": 0,
"icon": "sap-icon://decline"
} ]
};
var oTable = new sap.m.Table({
headerToolbar: new sap.m.Toolbar({
content: [new sap.m.Label({
text: ""
})]
}),
columns: [new sap.m.Column({
width: "2em",
header: new sap.m.Label({
text: "Kontrol Nesnesi"
})
}), new sap.m.Column({
width: "2em",
header: new sap.m.Label({
text: "Kontrol Sonucu"
})
}), new sap.m.Column({
width: "2em",
header: new sap.m.Label({
text: "Kontrol Edilecek"
})
})]
});
sap.ui.getCore().byId("tableWrapper").addItem(oTable); //Comment this code and uncomment the below code for table rendering
//this.getView().byId("SimpleFormChange480_TrialSonuc").addContent(oTable);
oTable.bindItems({
path: "/subvariants",
factory: this.populateItems.bind(this) //factory function
});
oTable.setModel(new sap.ui.model.json.JSONModel(summaryDetailData));
},
/* Factory function */
populateItems: function(sId, oContext) {
var oInput = null;
switch(oContext.getObject().type) {
case "comboBox":
oInput = new sap.m.ComboBox({ });
break;
case "input":
oInput = new sap.m.MultiInput({ });
break;
}
var oRow = new sap.m.ColumnListItem(sId, {
type: "Active",
cells: [
new sap.m.Text({ text: "{kontrolNesnesiTanim}" }),
new sap.m.Text({ text: "{kontrolNesnesiBelirtim}" }),
oInput
]
});
return oRow;
},