The model is the most import component in SAP UI5 application. The purpose of this post is to show you how to use it in different manner.
All example are based on this data source structure
{"menu": {
"id": "file",
"value": "File",
"popup": {
"menuitem": [
{"value": "New", "onclick": "CreateNewDoc()"},
{"value": "Open", "onclick": "OpenDoc()"},
{"value": "Close", "onclick": "CloseDoc()"}
]
}
}}
First, you have to find the model instance, then call the following method:
getProperty(sPath, oContext?)
sPath is important here, because it will indicate the wanted value.
Example 1: Get the value of value attribute
// Accès direct
Var oData = oModel.getProperty(« /menu/value ») ;
// Accès déroutée
Var oData = oModel.getProperty(“/menu”);
oData.value;
Example 2: Get the onClick value from the second line
// Accès direct
Var oData = oModel.getProperty(« /menu/popup/menuitem/1/onclick ») ;
// Accès dérouté
Var oData = oModel.getProperty(“/menu”);
oData.popup.menuitem[1].onclick;
Example 3: Change the id value attribute
oModel.setProperty(« /menu/value », newValue);
Example 4: Loop inside menuitem node
var oData = oModel.getProperty(“/menu/popup/menuitem”);
If (oData instanceof Array){
oData.foreach( function(oValue, i){
//…
});
}
Hope you will find those tips interesting.
Enjoy :wink:
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
5 | |
5 | |
5 | |
5 | |
4 | |
4 | |
4 | |
4 | |
3 | |
3 |