问题
I trying to migrate my app on new version of Openui5 (1.48) and have some problems with model bindings. I am using sap.ui.getCore().setModel(oModel, "local")
for model declaration and when I trying to bind some controls to values from this model like this:
<Text text="{local>/count}"/>
value isn't displayed but if I will get this model, set it to view in controller and remove >
from xml
var oModel = sap.ui.getCore().getModel("local");
this.getView().setModel(oModel);
XML
<Text text="{/count}"/>
everything would work fine. Maybe somebody had faced with similar problem or has an idea was wrong with my code?
EDIT
I solved the problem with solution suggested by @boghyon
new sap.ui.core.ComponentContainer({
//...,
propagateModel: true
})
回答1:
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"
.
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.
To learn more about where to set models, take a look at my answer to a similar question: https://stackoverflow.com/a/42251431/5846045
回答2:
I think problem may be how you creating the JSON model!,
try this one. Controller
sap.ui.define(["sap/ui/core/mvc/Controller",
"sap/ui/model/json/JSONModel",],
function(Controller,JSONModel) {
"use strict";
return Controller.extend("com.stackoverflow.testUI5", {
onInit:function(){
var oData = {
count:"1"
};
var oModel = new JSONModel(oData);
sap.ui.getCore().setModel(oModel , "local")
//this.getView().setModel(oModel ,"local");
}
});
});
XML View
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE xml>
<mvc:View controllerName="com.stackoverflow.testUI5"
xmlns:mvc="sap.ui.core.mvc"
xmlns:core="sap.ui.core" xmlns="sap.m" >
<Text text="{local>/count}"/>
</mvc:View>
this snippet will work.
来源:https://stackoverflow.com/questions/46894283/cant-bind-property-from-model-to-control-on-xml-view