on 12-29-2017 4:23 AM
Hi Exports,
I want to bind event name from JSON Model,
Let take a look at this example:
view.xml file
-------------------------
xmlns:tnt="sap.tnt"
...................................
<tnt:NavigationList id="navigationList" items="{/dataSet}">
<tnt:items>
<tnt:NavigationListItem text="{text}" select="{select}" />
</tnt:items>
</tnt:NavigationList>
--------------------------
controller.js file
--------------------------
var jsonModel = new sap.ui.model.json.JSONModel({
"dataSet":[
{text:"Project",
"select":"handleProjectSelect"}
]});
var oList = this.getView().byId("navigationList");
oList.setModel(jsonModel) ;
Here the problem which am facing is, handleProjectSelect event name is not triggering on click of respective navigationlist item.
Thanks,
Fathima
Hi Noor
here is an example. http://jsbin.com/lutocan/1/edit?html,js,output
IMO, you should have the event to call a function in your controller and let the controller does the job of finding the function in the model.
-D
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
The following code will work (I tested it on Web IDE).
View
<mvc:View controllerName="eventFromJson.controller.View1" xmlns:html="http://www.w3.org/1999/xhtml" xmlns:mvc="sap.ui.core.mvc"
displayBlock="true" xmlns:tnt="sap.tnt" xmlns="sap.m">
<App>
<pages>
<Page title="JSON evnets">
<content>
<tnt:NavigationList id="navigationList" items="{/dataSet}">
<tnt:items>
<tnt:NavigationListItem text="{text}"/>
</tnt:items>
</tnt:NavigationList>
</content>
</Page>
</pages>
</App>
</mvc:View>
Controller
sap.ui.define([
"sap/ui/core/mvc/Controller",
"sap/m/MessageToast",
"sap/ui/model/json/JSONModel"
], function(Controller, MessageToast) {
"use strict";
return Controller.extend("eventFromJson.controller.View1", {
handleProjectSelect: function() {
MessageToast.show("handleProjectSelect");
},
onInit: function() {
var jsonModel = new sap.ui.model.json.JSONModel({
"dataSet": [{
"text": "Project",
"select": "handleProjectSelect"
}]
});
var oList = this.getView().byId("navigationList");
oList.setModel(jsonModel);
var items = oList.getItems();
items[0].attachSelect(this[jsonModel.getData().dataSet[0].select]);
}
});
});
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Fathima,
Try like this
"dataSet":[
{text:"Project",
"select": this.handleProjectSelect}
]});
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
88 | |
10 | |
10 | |
9 | |
7 | |
7 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.