#tipoftheday will be a series of blog post that I’m mirroring from my Medium account.
sap.ui.define([
"sap/ui/core/UIComponent",
"sap/ui/model/json/JSONModel"
], function(UIComponent, JSONModel) {
"use strict";
return UIComponent.extend("com.openui5.example.Component", {
metadata: {
manifest: "json"
},
init: function() {
// call the base component's init function
UIComponent.prototype.init.apply(this, arguments);
//Create the model and load data from the local JSON file
var oModel = new JSONModel("./model/init_data.json");
oModel.setDefaultBindingMode("OneWay");
// set the device model
this.setModel(oModel, "init_data");
}
});
});
Why waste time and code when you can simply load it directly from the manifest.json?
I’ve created a stripped manifest that will show you only the interesting parts to copy/past.
{
"_version": "1.1.0",
"sap.app": {
"dataSources": {
"init_data_alias": {
"uri": "model/init_data.json",
"type": "JSON"
}
}
},
"sap.ui5": {
"_version": "1.1.0",
"models": {
"i18n": {
"type": "sap.ui.model.resource.ResourceModel",
"settings": {
"bundleName": "com.openui5.example.i18n.i18n"
}
},
"init_data": {
"type": "sap.ui.model.json.JSONModel",
"dataSource": "init_data_alias"
}
}
}
}
Pretty easy uh?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
8 | |
8 | |
7 | |
6 | |
5 | |
4 | |
4 | |
4 | |
3 | |
3 |