gpt4 book ai didi

javascript - getBindingContext() 获取未定义的属性

转载 作者:行者123 更新时间:2023-11-30 09:48:18 25 4
gpt4 key购买 nike

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

这是我的数据模型:

{
"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>

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

我的 Controller :

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")
});
}

最佳答案

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

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

关于javascript - getBindingContext() 获取未定义的属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37813610/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com