0

我已经通过 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;
          });
4

2 回答 2

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) {
    }
  }); 
}
于 2013-05-03T16:25:00.000 回答
0

您打印到控制台的对象是Person模型的实例。当您要求集合获取数据时,就会发生这种情况。它从服务器获取数据,将该数据转换为模型实例,并将这些模型实例的列表存储为集合内容。也许您可以进一步澄清您的问题。

于 2013-05-03T16:04:24.640 回答