<script>
sap.ui.core.Control.extend("com.controls.MyButton", {
metadata: {
aggregations: {
buyButton : { type: "sap.ui.commons.Button", multiple: false}
},
events: {
buy: {enablePreventDefault: true}
}
},
init: function() {
var oControl = this;
//create a button to allow used buying that book
var oBuyBtn = new sap.ui.commons.Button({
text: "Click Me",
press: function (oEvent) {
oControl.fireBuy({
someData : "some data I want to pass along with the event object"
});
}
});
this.setAggregation("buyButton", oBuyBtn);
},
renderer: {
render: function(oRm, oControl) {
oRm.renderControl(oControl.getAggregation("buyButton"));
}
}
});
var oButton = new com.controls.MyButton({
buy: function(oEvent) {
alert(oEvent.someData);
}
});
oButton.placeAt("content");
</script>
代码如上所示。我想在更改回调函数中获取someData属性,我怎么可能实现呢?我尝试了oEvent.someData,但是我得到了未定义的警报。代码来自nabisoft网站,但没有解释如何访问fireBuy方法传递的对象。
答案 0 :(得分:0)
oEvent.getParamter(“someData”)解决了这个问题!
答案 1 :(得分:0)
var oButton = new com.controls.MyButton({
buy: function(oEvent) {
alert(oEvent.getParameter("someData"));
}
});