我已经通过parse.com上的apirest在骨干中获取了一个集合,但是在console.log中我可以读取这个结果: child {collection:child,attributes:Object,_escapedAttributes:Object,cid:“c2”,changed:Object ...}。
那么结果在哪里?在我的收藏中有名字的用户,用户名为ecc ..
var HomeView = Backbone.View.extend({
template: Handlebars.compile(template),
events: {
},
initialize: function() {
console.log("inhomeview");
var amici = new Usercollection();
amici.fetch({
success: function(collection) {
amici.each(function(object) {
console.warn(object);
console.log(object);
});
},
error: function(amici, error) {
// The collection could not be retrieved.
}
});
收集:
var Usercollection = Backbone.Collection.extend({
model:Person,
url:'https://api.parse.com/1/classes/User',
型号:
var Person = Backbone.Model.extend({
defaults:{
},
initialize:function(){
console.log("inperson");
},
validate:function(){
console.log("validate");
},
send:function(){
var user = new Parse.User();
user.set("username", this.get("username"));
user.set("password", this.get("password"));
user.set("email", this.get("email"));
// other fields can be set just like with Parse.Object
//user.set("phone", "415-392-0202");
user.signUp(null, {
success: function(user) {
// Hooray! Let them use the app now.
},
error: function(user, error) {
// Show the error message somewhere and let the user try again.
alert("Error: " + error.code + " " + error.message);
}
});
}
});
return Person;
});
答案 0 :(得分:1)
amici.models包含您要拉的对象
每个模型都是人
initialize: function() {
var amici = new Usercollection();
amici.fetch({
success: function(collection) {
amici.models.each(function(person) {
console.log(person);
console.log(person.attributes);
});
},
error: function(amici, error) {
}
});
}
答案 1 :(得分:0)
您要打印到控制台的对象是Person
模型的实例。当您要求集合获取数据时会发生这种情况。它从服务器获取数据,将该数据转换为模型实例,并将这些模型实例的列表存储为集合内容。也许你可以进一步澄清你的问题。