我不确定是否还有"最佳实践",我真的认为只有'一种'做法;-)但是我很想学习其他任何一种,所以如果有人可以对此发表评论,请不要犹豫!
我认为一般的想法只是定义你的事件; 然后UI5框架自动生成注册(attach<YourEvent>),取消注册(detach<YourEvent>)和触发事件(fire<YourEvent>)的方法.
例如:
return ControlToExtend.extend("your.custom.Control", {
metadata: {
properties: {
// etc...
},
aggregations: {
"_myButton": {
type: "sap.m.Button",
multiple : false,
visibility: "hidden"
},
// etc...
},
associations: {
// etc...
},
events: {
yourCustomEvent: {
allowPreventDefault: true,
parameters: {
"passAlong": { type: "string" }
}
}
}
},
init: function() {
ControlToExntend.prototype.init.apply(this, arguments);
var oControl = this, oMyButton;
oMyButton = new Button({ // Button required from "sap/m/Button"
// ...,
press: function (oEvent) {
oControl.fireYourCustomEvent({
passAlong: "Some dummy data to pass along"
});
}
});
this.setAggregation("_myButton", oMyButton);
},
// etc...
});
Run Code Online (Sandbox Code Playgroud)
希望这能解释一下
| 归档时间: |
|
| 查看次数: |
7644 次 |
| 最近记录: |