ODataModel 聚合的 getBindingContext() 返回未定义 [英] ODataModel aggregation's getBindingContext() returns undefined
问题描述
我有一个 sap.m.VBox
控件,其中 items
聚合绑定到 ODataModel 数据集,因此由 填充sap.m.HBox
模板控件包含多个 sap.m.Input
控件(绑定到相应的 ODataModel 的数据集属性)
I have a sap.m.VBox
control, of which the items
aggregation is bound to an ODataModel dataset, and as such is being populated by a sap.m.HBox
template control containing multiple sap.m.Input
controls (which are bound to the respective ODataModel's dataset properties)
在代码中:
<VBox items="{/My_ODatamodel_Dataset}">
<items>
<HBox>
<Input value="{property1} change="doSomething"/>
<Input value="{property2} change="doSomething"/>
<Input value="{property3} change="doSomething"/>
</HBox>
</items>
</VBox>
(OData 数据集应用了过滤器,但为简洁起见我将其省略)
(the OData dataset has a filter applied, but I left it out for brevity)
因此,渲染结果将是一个 VBox,其中包含多行 HBox(我的 OData 集中的每个条目一个)包含这些条目的输入字段.
The rendered result will thus be a VBox with multiple rows of HBoxes (one for each entry in my OData set) containing the input fields for these entries.
在我的控制器中,我有 doSomething
方法:
In my controller, I have the doSomething
method:
doSomething: function(oEvent) {
var oCurrentContext = oEvent.getSource().getBindingContext();
var sSomeHiddenValue = oCurrentContext().getProperty("property4");
// continue to do something special with hidden property 4
}
然而,令我惊讶的是 oEvent.getSource().getBindingContext()
返回 undefined
...
However, to my surprise oEvent.getSource().getBindingContext()
returns undefined
...
我想我在这里忽略了一些东西,但是当使用 JSON 模型而不是 OData 模型时它确实工作......
I suppose I'm overlooking something here, but it does work when using a JSON model instead of an OData model...
我想要实现的是从我正在进行更改的当前条目中获取属性值.是否有使用 OData 模型的不同方法?
What I'm trying to achieve, is to get a property value from the current entry in which I'm making a change. Is there a different way of doing so using an OData model?
非常感谢任何帮助!
推荐答案
有了ODataModel你需要从Model中获取上下文的属性,试试
with the ODataModel you need to get the properties of the context from the Model, try
var oModel = oEvent.getSource().getModel();
var oContext = oEvent.getSource().getBindingContext();
var sSomeHiddenValue = oModel.getProperty("property4", oContext);
第jsp
这篇关于ODataModel 聚合的 getBindingContext() 返回未定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!