0

I created javascript view

 sap.ui.jsview("view.taskListView", {

/** Specifies the Controller belonging to this View. 
* In the case that it is not implemented, or that "null" is returned, this View does not have a Controller.
* @memberOf view.taskListView
*/ 
getControllerName : function() {
    return "view.taskListView";
},

/** Is initially called once after the Controller has been instantiated. It is the place where the UI is constructed. 
* Since the Controller is given to this method, its event handlers can be attached right away. 
* @memberOf view.taskListView
*/ 
createContent : function(oController) {

    var oLabel = new sap.m.Label("l1",{ text :"Weekly Tasks", textAlign:"Center", width:"100%"}); 
  //  var oList = new sap.m.List({noDataText:"No data", items:"{/modelData}"});


   var oList=  new sap.m.List({    // define List Control

     //   mode: "MultiSelect",    // multi selection mode
    columns : [
        new sap.m.Column({  // first column
    }), 
    new sap.m.Column({  // second column
    })
], 
items : [
    new sap.m.ColumnListItem({  // first row
        type : "Navigation",
        //selected : true,    // first item is selected (from ListItemBase)
        cells : [
            new sap.ui.core.Icon({
                src : "{/iconTaskSource}",
                size : "1.5em"
            }),
            new sap.m.Text({       // second cell related to second column definition
                text : "{/taskName}"  
            })
        ]
    }),
    new sap.m.ColumnListItem({  // second row
       type : "Navigation",
        cells : [
            new sap.ui.core.Icon({
                src : "{/iconTaskSource}",
                size : "1.5em"

            }),
            new sap.m.Text({       // second cell related to second column definition
                text : "{/taskName}"
            })
        ]
    })  
]
  });


    return new sap.m.Page({
        title: "Title",
        content: [
            oLabel , oList
            /*
            new sap.m.Button({
               text:"Go to Page2",
               tap: function(){
                    //app.to("abc.SecondPage");
                    alert("Hello");
               }                   
          })
          */
        ]

    });
}

});

and controller

   sap.ui.controller("view.weeklyTasks", {

onInit: function() {



   var aData2 = { modelData : [ 

      {iconTaskSource:"icon1", taskName: "task1"},
      {iconTaskSource:"icon2", taskName: "task2"}


    ]};


  var oModel = new sap.ui.model.json.JSONModel(aData2);
  this.getView().setModel(oModel2);

}

});

The binding is not working Did I miss something ?

10
  • Yes, remove the slashes preceding {/iconTaskSource} and {/taskName}. Since your List is bound to {/modelData}, the list items should be bound relatively to this node. Commented Nov 4, 2014 at 9:06
  • I fixed it but it still didn't work Commented Nov 4, 2014 at 10:38
  • also I didn't see the path attribute in the API of sap.m.list so maybe i need to delete it ? Commented Nov 4, 2014 at 10:43
  • in my opinion you should bind the model to the list, not to the view.. does it work if you got it all the code in the view? Commented Nov 4, 2014 at 10:44
  • @Zyrex - can you show me an example ? I didn't understand how to bind the model to the list Commented Nov 4, 2014 at 10:45

2 Answers 2

2

Try running this code snippet.

sap.ui.jsview("view.taskListView", {

            getControllerName: function() {
                return "view.taskListView";
            },


            createContent: function(oController) {

                var oLabel = new sap.m.Label("l1", {
                    text: "Weekly Tasks",
                    textAlign: "Center",
                    width: "100%"
                });
                var oList = new sap.m.List({ // define List Control
                    columns: [
                        new sap.m.Column({ // first column
                        })
                    ]
                });
                var oTemplate = new sap.m.ColumnListItem({
                    type: "Navigation",
                    cells: [
                        new sap.m.Text({
                            text: "{taskName}"
                        })
                    ]
                });
                oList.bindItems('/modelData', oTemplate);
                return new sap.m.Page({
                    title: "Title",
                    content: [
                        oLabel, oList
                    ]

                });
            }
        });

        sap.ui.controller("view.taskListView", {

            onInit: function() {

                var aData2 = {
                    modelData: [

                        {
                            iconTaskSource: "icon1",
                            taskName: "task1"
                        }, {
                            iconTaskSource: "icon2",
                            taskName: "task2"
                        }
                    ]
                };

                var oModel = new sap.ui.model.json.JSONModel(aData2);
                this.getView().setModel(oModel);
            }
        });

        var oApp = new sap.m.App();
        var myView = sap.ui.view({
            type: sap.ui.core.mvc.ViewType.JS,
            viewName: "view.taskListView"
        });
        oApp.addPage(myView);
        oApp.placeAt('content');
<!DOCTYPE html>
<html>
<head>
    <meta http-equiv='X-UA-Compatible' content='IE=edge' />
    <title>test</title>

    <script id='sap-ui-bootstrap' type='text/javascript' src='https://openui5.hana.ondemand.com/resources/sap-ui-core.js' data-sap-ui-theme='sap_bluecrystal' data-sap-ui-libs='sap.m'></script>

</head>

<body class='sapUiBody'>
    <div id='content'></div>
</body>

</html>

Check this for the fixed version of your code http://jsbin.com/kequme/1/edit

Sign up to request clarification or add additional context in comments.

5 Comments

thanks , If I don't want to do it with template how I can do the binding ?
Then, you have to manually enter the binding path for all the list items. Ex - {/modelData/0/taskName}
can you show me an example example without template or how I can fix my example ? Did the binding in the list to path parameter is correct ?
Where do I need to add the binding path for the list item in which element ?
You should have given the binding path as {/modelData/0/taskName} & {/modelData/1/taskName} instead of {/taskName}.
0

You neeed to include data-sap-ui-xx-bindingSyntax="complex" in index.html file. Look:

<script src="resources/sap-ui-core.js" id="sap-ui-bootstrap"
data-sap-ui-xx-bindingSyntax="complex" data-sap-ui-libs="sap.m"
data-sap-ui-theme="sap_bluecrystal">
    </script>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.