使用 OpenUI5/SAPUI5,根据文档XML 绑定表达式 https://help.sap.com/saphelp_nw74/helpdata/en/da/f6852a04b44d118963968a1239d2c0/content.htm,我们有能力从视图执行函数。
new sap.m.CheckBox({
selected: "{= checkSelectedItems(${odata>CustomerId}) }"
})
在我的视图后面的控制器中:
checkSelectedItems: function(sCustomerId) {
return true;
}
在我看来,我得到了一般错误,就好像它找不到我的函数一样:
Uncaught TypeError: Cannot read property 'apply' of undefined
我尝试通过多种方式调用该函数:
{= .checkSelectedItems() }
{= my.namespace.checkSelectedItems() }
我什至尝试在索引页的脚本标记中添加一个函数,以查看它是否只能访问全局函数,但我也无法触发该函数。建议?我是否误解了文档?
请参阅此处的 JS Bin:http://jsbin.com/sosotacihi/edit?html,输出 http://jsbin.com/sosotacihi/edit?html,output。我已经注释掉了有问题的复选框,但如果您将其放入,您会看到错误。
您需要使用格式化程序从 XML 视图调用控制器的方法。
new sap.m.CheckBox({
selected: "{parts:['odata>CustomerId'], formatter:'.checkSelectedItems'}"
});
这可以应用于任何事件触发属性。提到这一点的通用方法是:
{parts:['<parameter1>', '<parameter2>', ...], formatter:'.<methodInController>'}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)