Set API result into model
Collapse
X
-
Had a similar situation, needed to invoke this.getModelFactory() method inside an ajax call:
That worked for me, try:Code:var jqxhr = $.ajax(url).done(function (data) { this.linkDisplayEntity = data['parentType']; this.linkDisplayEntityId = data[this.linkDisplayAttribute]; alert("this.getModelFactory() = "+this.getModelFactory()); // displays " [object Object] " so 'this' is now available inside the function }.bind(this));
var jqxhr = $.getJSON('User/' + this.model.get('assignedUserId'), function (json) {
this.model.set('confident',json.region);
} .bind(this));
Hope it helps. -
Hello Team,
Anyone have solutions?
Please let me know.
Thanks.Leave a comment:
-
Hi Tanya,
Added this.
$.getJSON('User/' + this.model.get('assignedUserId'), function (json) {
this.model.set('confident',json.region);
}, this);
---- STILL I GET THE SAME ERROR in CONSOLE----
Please give me the solution to fix that, You only asked me to set the API result into a userModel.
Now i am asking you to help in setting the result object to that model.
You just replied why my code is not working, But i didn't ask for that.
Please do understand that all developers in your forum are not same in their expertise.
So please guide them to resolve the issue if they ask for help.
Thanks.1 PhotoLast edited by VigneshChinnaiyan; 07-19-2018, 12:24 AM.Leave a comment:
-
Set API result into model
Hello,
In phone.js
I am using this API to get the user Object.
$.getJSON('User/' + this.model.get('assignedUserId'), function (json) {
this.model.set('confident',json.region);
});
How to set the result json.region into model?
setup: function () {
this.dataFieldName = this.name + 'Data';
this.defaultType = this.defaultType || this.getMetadata().get('entityDefs.' + this.model.name + '.fields.' + this.name + '.defaultType');
if (this.model.has('doNotCall')) {
this.listenTo(this.model, 'change:doNotCall', function (model, value, o) {
if (this.mode !== 'detail' && this.mode !== 'list') return;
if (!o.ui) return;
this.reRender();
}, this);
}
$.getJSON('User/' + this.model.get('assignedUserId'), function (json) {
this.model.set('confident',json.region);
});
},
I get the ERROR in console : Uncaught TypeError: Cannot read property 'set' of undefined
How to fix this?
Thanks.Last edited by VigneshChinnaiyan; 07-15-2018, 03:04 AM.

Leave a comment: