这是我的代码,它不起作用。
var that = this;
otable.bindItems("/", new sap.m.ColumnListItem({
cells: [new sap.m.Button({
text: "Hello",
id: "buttonid",
press: [that.handleButtonPress, this]
})]
}));
otable.setModel("data");
handleButtonPress: function () {
var Button_ = this.getView().byId("buttonid");
}
如何设置动态ID?
答案 0 :(得分:1)
要创建动态ID,您必须在聚合绑定上使用factory function:
oTable.bindItems("/", function(sId, oContext) {
return new sap.m.ColumnListItem({
cells: [
new sap.m.Button("yourDynamicID", {
text: "Hello",
press: [that.handleButtonPress, this]
})
]
};
});
答案 1 :(得分:0)
Id
是Button构造函数的第一个参数。
var oButton = new sap.m.Button("id", {
text: "myButton"
});
答案 2 :(得分:0)
如果您没有向Control
构造函数提供id,则会自动生成id。然后,您可以使用事件参数访问按下的按钮:
var that = this;
otable.bindItems("/", new sap.m.ColumnListItem({
cells: [new sap.m.Button({
text: "Hello",
press: [that.handleButtonPress, this]
})]
}));
otable.setModel("data");
handleButtonPress: function (oEvent) {
var Button_ = oEvent.getSource();
}