【问题标题】:getBindingContext() getProperty of undefinedgetBindingContext() getProperty of undefined
【发布时间】:2016-10-15 06:43:39
【问题描述】:

我在获取listItem 的绑定上下文时遇到了问题

这是我的数据模型:

{
  "Items": [
        {
            "ItemTypeID": "0",
            "Name": "A"
        },
        {
            "ItemTypeID": "1",
            "Name": "B"
        },
        {
            "ItemTypeID": "2",
            "Name": "C"
        }
    ]
}

我的看法:

<List id="idItemTypes" mode="SingleSelectMaster" select="handleListSelect"
            items="{itemTypes>/ItemTypes}">
            <items>
                <StandardListItem title="{itemTypes>Name}" type="Navigation" />             
            </items>
        </List>

我的视图工作正常,并显示了我模型中的所有项目。但是,如果我从列表中选择一个项目,我将无法获得绑定上下文。它一直是未定义的。

我的控制器:

handleListSelect : function(oEvent) {
    this._showDetail(oEvent.getParameter("listItem"));
},
_showDetail : function(oItem) {
    this.getRouter().navTo("Items", {
        console.log( oItem.getBindingContext() ); //undefined
        ItemTypeID : oItem.getBindingContext().getProperty("ItemTypeID")
    });
}

【问题讨论】:

标签: javascript data-binding sapui5


【解决方案1】:

一个常见错误:如果您使用命名模型,请不要忘记将模型名称指定为 getBindingContext 方法的参数 :-)

this.getRouter().navTo("Items", {
    console.log( oItem.getBindingContext("itemTypes") ); //should now hold an object
    ItemTypeID : oItem.getBindingContext("itemTypes").getProperty("ItemTypeID")
});

【讨论】:

    猜你喜欢
    • 2019-02-12
    • 2013-01-15
    • 1970-01-01
    • 2021-06-25
    • 2018-12-16
    • 2021-01-08
    • 2020-01-21
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多