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

标签 javascript data-binding sapui5

我在获取 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/

相关文章:

javascript - 如何设置内含 sap.ui.table.Table 的 SAPUI5 对话框的响应大小?

javascript - 如何加载特定目录下的所有本地资源?

javascript - Codeigniter:由于tinymce文本区域而没有进行验证

javascript - 找到两个常量之间和一个常量之后的子字符串的值

javascript - 如何使用 d3js 在循环中为圆环图添加工具提示

winforms - Winforms MVP

c# - Xamarin 在哪里执行绑定(bind)表达式?

data-binding - 数据绑定(bind)文本框

javascript - sap.m.表 : How to scroll to given listItem

javascript - 隐藏列时,Jqgrid 失去全宽