When this line is executed, the corresponding JavaScript file for JSONModel will be downloaded. We have already learned this "UI5 module lazy load mechanism" in the first blog.
Let's review our learning regarding prototype chain so far: BaseObject -> EventProvider -> ManagedObject -> Element -> Control.
This prototype chain can be found from the call-stacks below. The root node in the prototype chain is again BaseObject. The whole chain is:
BaseObject -> EventProvider -> MessageProcessor -> Model -> ClientModel -> JSONModel
From the source code of JSONModel we can also know that our codes in the sample application regarding JSON model initialization could even be reduced.
Original code:
var oModel = new sap.ui.model.json.JSONModel();
var myData = {"field_for_text": "Jerry"};
oModel.setData(myData);
Reduced code:
var oModel = new sap.ui.model.json.JSONModel( {"field_for_text": "Jerry"} );
However in order to figure out what has happened during each line execution, I keep to use the original lengthy code.
In Model's constructor, we can find the three default Supported binding modes:
Since I have not passed any data into the JSONModel constructor, so new sap.ui.model.json.JSONModel() will only return an empty JSON Model instance.
Nothing special, just create a new object for later usage.
We don't specify any value for parameter bMerge, so simply assign the oData passed in to this.oData ( line 66 ).
In checkUpdate, since so far the JSON model instance has no binding assigned, so it will do nothing and just return.
This line binds the JSON model instance to button instance.
line 32200: so far, there is not any BindingContext to be updated, since till now we only bind the Button control as a whole to the JSON model, but never bind any Button property to JSON model field yet. The variable this.mBindingInfos in line 32067 is empty, so again the function updateBindingContext, as well as updateBindings ( line 32202 ) just return.
The binding information is stored in the central array this.mBindingInfos and after that _bindProperty function is called.
The main logic of control binding with JSON Model field is done in this function.
1. In line 31319, a binding instance is created by oModel.bindProperty.
2. In line 31331, the created binding instance is inserted to array aBindings.
The implementation of this function:
JSONModel.prototype.bindProperty = function(sPath, oContext, mParameters) {
var oBinding = new JSONPropertyBinding(this, sPath, oContext, mParameters);
return oBinding;
};
Here we have learned the third prototype chain:
BaseObject -> EventProvider -> Binding -> PropertyBinding -> ClientPropertyBinding -> JSONPropertyBinding
The value for Button property "text" to be displayed in the UI, is maintained in this very JSONPropertyBinding instance and filled in the constructor of ClientPropertyBinding.
This function extracts the data from the field oData of model instance by property name.
So far, the control property binding is done. What is the status of Button control after bindProperty function is executed? Starting from control instance, we can find the value of text property to be displayed from the path oButton1.mBindingInfos.text.binding.oValue, which is filled by function _getValue we have learned in the previous step.
This is the reason why we see "Jerry" in the final rendered UI.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
10 | |
10 | |
10 | |
9 | |
8 | |
8 | |
6 | |
6 | |
5 | |
5 |