Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
608 views
in Technique[技术] by (71.8m points)

sapui5 - Control with bound property doesn't display model data in the UI

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}" />

... the value isn't displayed.

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...