How to extend a JSONModel
How to extend a JSONModel
So here’s a very basic template for extending the JSONModel.
sap.ui.define([
"sap/ui/model/json/JSONModel",
"sap/base/Log"
], function (JSONModel, Log) {
return JSONModel.extend("XXX.model.XXX", {
/**
* @class XXX
* @summary XXX
* @extends sap.ui.model.json.JSONModel
* @param {Object} controller - this
* @example
* this.setModel( new XXX(this), "XXX");
*/
constructor: function (controller) {
JSONModel.prototype.constructor.call(this, []);
this._oParentController = controller || void 0;
this._oServiceModel = this._oParentController.getModel();
Log.info("XXX.js initialized");
},
/**
* @memberOf XXX
* @description XXX
* @example
* this.getModel("XXX").getXXX();
*/
getXXX: function () {
}
});
});
I always pass the “this” context in the constructor to get access to the servicemodels and other stuff.
this._oParentController = controller || void 0;
Aswell most of the times I only use one servicemodel so I also declare it in the constructor.
this._oServiceModel = this._oParentController.getModel();
That’s it. If you are interested in more examples:
Comments
Post a Comment