Answer the question
In order to leave comments, you need to log in
Why is the value not displayed in a fairly simple backbone.js code?
Hello.
What am I doing wrong in this code
// App
window.App = {
Models: {},
Collections: {},
Views: {}
}
// User
App.Models.User = Backbone.Model.extend({
url: 'https://jsonplaceholder.typicode.com/users/1'
});
var User = new App.Models.User();
User.fetch();
console.log( User );
console.log( User.get('name') );
// App
window.App = {
Models: {},
Collections: {},
Views: {}
}
// User
App.Models.User = Backbone.Model.extend({
url: 'https://jsonplaceholder.typicode.com/users/1',
checkAuth: function(){
this.fetch({
success: function(mod, res){
console.log('Успешно');
console.log(res.name);
},
error:function(mod, res){
console.log('Не успешно');
}
});
}
});
var User = new App.Models.User();
User.checkAuth();
Answer the question
In order to leave comments, you need to log in
// User
App.Models.User = Backbone.Model.extend({
urlRoot: 'https://jsonplaceholder.typicode.com/users/',
checkAuth: function () {
var options = {
success: function (mod, res) {
console.log('Успешно');
console.log(res.name);
},
error: function (mod, res) {
console.log('Не успешно');
}
}
this.fetch(options);
}
});
var userID = 1;
var user = new App.Models.User({
id: userID
});
user.checkAuth();
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question