带有绑定属性的控件不会在 UI 中显示模型数据 [英] Control with bound property doesn't display model data in the UI

查看:15
本文介绍了带有绑定属性的控件不会在 UI 中显示模型数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将我的应用程序迁移到新版本的 OpenUI5 (1.48),并且在模型绑定方面遇到了一些问题.我正在使用 sap.ui.getCore().setModel(oModel, "myModel") 进行模型声明,当我尝试将一些控件绑定到这个模型的值时......

I'm migrating my app to new version of OpenUI5 (1.48) and have some problems with model bindings. I am using sap.ui.getCore().setModel(oModel, "myModel") for model declaration and when I'm trying to bind some controls to values from this model like this ...

<Text text="{local>/count}" />

...该值未显示.

但是如果我得到这个模型,请将其设置为在控制器中查看...

But if I get this model, set it to view in controller ...

var oModel = sap.ui.getCore().getModel("local");
this.getView().setModel(oModel);

<Text text="{/count}" />

...一切正常.也许有人遇到了类似的问题,或者知道我的代码有什么问题?

... everything would work fine. Maybe somebody faced a similar problem or has an idea what is wrong with my code?

推荐答案

您必须在您的应用中使用 Component.在这种情况下,核心模型不会自动传播到 ComponentContainer 的子代,这就是为什么您的 Text 控件不知道模型 "local".

You must be using a Component in your app. In that case, core models are not automatically propagated to the children of the ComponentContainer which is why your Text control doesn't know the model "local".

"{/count}" 之所以有效,是因为您在没有任何模型名称的情况下在视图上显式设置了模型.如果模型没有名称,则它是默认模型,并且必须在绑定路径中省略 >.

The reason why "{/count}" works is because you set the model explicitly on the view without any model name. If the model doesn't have a name, it's a default model and > has to be omitted in the binding path.

要了解有关在哪里设置模型的更多信息,请查看我对类似问题的回答:https://stackoverflow.com/a/42251431/5846045

To learn more about where to set models, take a look at my answer to a similar question: https://stackoverflow.com/a/42251431/5846045

这篇关于带有绑定属性的控件不会在 UI 中显示模型数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆