我正在编写一个在运行时加载了 sap.m.Table
的 SAPUI5 应用程序。我想使用 Controller 内部定义的 factory
方法(这是最好的方法吗?)。为此,在获取模型后,我必须将表的聚合(items
)绑定(bind)到该模型:
tableSeason.bindAggregation("items", {
path: "/results",
factory: this.tableFactory
});
很遗憾,这段代码不起作用,因为函数 tableFactory
内部调用了 this
。
tableFactory
的原型(prototype)是tableFactory: function(sId, oContext){...}
。
我不想将整个代码放在 tableFactory
函数中,有人可以建议一种解决此问题的方法吗?
谢谢, 加布里埃尔
最佳答案
如果您想将函数附加到工厂:
this.tableFactory.bind(this)
如果你想立即调用函数
this.tableFactory.call(this)
this.tableFactory.apply(this)
关于javascript - 绑定(bind)在匿名对象中定义的函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44181963/