Sapui5 DataReceived事件无法激发?

Sapui5 DataReceived事件无法激发?,sapui5,Sapui5,我正在使用SAPUI5实现一个主详细信息应用程序,当第一次打开应用程序时,URL哈希为空,我希望将哈希设置为主列表中的第一项,但我无法触发dataReceived事件来确定是否完成了列表加载。有什么想法吗 manifest.json: { "sap.app": { "dataSources": { "mainService": { "uri": "XXX", "type": "JSON

我正在使用SAPUI5实现一个主详细信息应用程序,当第一次打开应用程序时,URL哈希为空,我希望将哈希设置为主列表中的第一项,但我无法触发dataReceived事件来确定是否完成了列表加载。有什么想法吗

manifest.json:

{
    "sap.app": {
        "dataSources": {
            "mainService": {
                "uri": "XXX",
                "type": "JSON"
            }
        },
        ...
}
Master.view.xml:

<List items="{path: '/'}">
        ...
</List>

Ref:

根据上面的代码,我可以假设您有一个由组件通过应用描述符(=manifest.json)创建的JSONModel,因此我们讨论的是“自动”创建模型。我想JSONModel成功地加载了数据。。。然而,所有这些都发生在应用程序的早期阶段。换句话说,您的事件处理程序将永远不会被调用,因为数据已经加载,并且在加载数据之后附加事件处理程序意味着您可能太晚才附加事件处理程序

顺便说一句:我建议使用attachEvent()直接在onInit()中执行,而不是在\onMasterMatched()中附加处理程序(每次)。这只是一个提示,对你的情况没有帮助

建议:
如何在onInit()中的Master.controller.js内的JSONModel中创建?在这里,您可以轻松地附加事件处理程序。我甚至更喜欢这样,因为主列表的数据属于主视图/控制器,因此我不会将其放入应用程序描述符中。但是,由于我没有真正意识到这些需求,我可能在这里错了…

另一种获得列表初始更新通知的方法是在onInit处理程序中使用


当列表“接收”并绑定数据时,将触发事件处理程序
onInitialUpdateFinished

dataReceived
相反,事件
updateFinished
即使在JSONModel中也能工作,无论何时实际接收数据:
onInit : function () {
    this.getRouter().getRoute("master").attachPatternMatched(this._onMasterMatched, this);
}
/**
* If the master route was hit (empty hash) we have to set
* the hash to to the first item in the list as soon as the
* listLoading is done and the first item in the list is known
* @private
*/
_onMasterMatched :  function() {
    console.log(this._oList.getBinding("items") instanceof sap.ui.model.Binding) // return ture
    this._oList.getBinding("items").attachEventOnce("dataReceived",
        function(oData) {
            //did not call 
            var oFirstListItem = this._oList.getItems()[0]; 
        });
}
onInit: function() {
  this.byId("list").attachEventOnce('updateFinished', this.onInitialUpdateFinished, this);
},