本文介绍了SAPUI5表达式绑定的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 是否可以将控件属性绑定到具有动态属性名称的模型,例如,存储在另一个模型字段中?我以为我们可以为此目的使用SAPUI5 表达式绑定,但它没有无法正常工作:跟踪窗口中的绑定被破坏,表达式似乎根本无法评估。 XML视图 < TextArea value = {= $ {StackOverflow> / bindTextAreaTo}} /> 控制器 oModel = this.getView()。getModel( StackOverflow); / * *模型具有两个属性:问题和注释 *我希望根据某些条件将TextArea的值绑定到其中之一* / oModel.setProperty( / question,); oModel.setProperty( / comment,); oModel.setProperty( / bindTextAreaTo, bAsk? StackOverflow> / question: StackOverflow> / comment); 解决方案否,目前无法实现。 但是,对于您要执行的操作有一个简单的解决方法(请参见下文)。 基本上,您创建一个视图模型并在该模型上设置一些布尔值。然后在表达式绑定中使用此标志来动态定义应使用哪种模型的属性... XMLView < TextArea value = {= $ {view> / ask}?$ {StackOverflow> / question}:$ {StackOverflow> / comment}} /> 控制器 var oModel = this.getView()。getModel( StackOverflow); oModel.setProperty( / question,); oModel.setProperty( / comment,); // ... var oViewModel = new sap.ui.model.json.JSONModel(); this.getView()。setModel(oViewModel, view); // ... oViewModel.setProperty( / ask,bAsk); Is it possible to bind control property to model with dynamic property name, stored, for instance, within another model field? I thought we can use SAPUI5 Expression Binding for this purpose, but it doesn't work: binding in trace window is broken and expression seems to be not evaluated at all.XML View<TextArea value="{= ${StackOverflow>/bindTextAreaTo} }" />ControlleroModel = this.getView().getModel("StackOverflow");/* * The model have two properties: question and comment * I want value of TextArea to be bound to one of them based on some condition */oModel.setProperty("/question", "");oModel.setProperty("/comment", "");oModel.setProperty("/bindTextAreaTo", bAsk ? "StackOverflow>/question" : "StackOverflow>/comment" ); 解决方案 No, that's currently not possible.However, there is a simple workaround for what you want to do (see below).Basically, you create a view model and set some boolean value on the model. This flag is then used in your expression binding to define "dynamically" what property of what model shall be used...XMLView<TextArea value="{= ${view>/ask} ? ${StackOverflow>/question} : ${StackOverflow>/comment} }" />Controllervar oModel = this.getView().getModel("StackOverflow");oModel.setProperty("/question", "");oModel.setProperty("/comment", "");//...var oViewModel = new sap.ui.model.json.JSONModel();this.getView().setModel(oViewModel, "view);//...oViewModel.setProperty("/ask", bAsk); 这篇关于SAPUI5表达式绑定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
08-12 04:20