2

I am creating a collection that has an external url something like this:

var todoCollection = Backbone.Collection.extend({
    model: Todo

    url: function() {
        return "http:externalurl.com";
    },

    parse: function(dat) {
        return dat.obj.data;
    }
});
return new todosCollection;​

and my model looks like this:

var TodoModel = Backbone.Model.extend({
    initialize: function() {}
});
return TodoModel;​

Now here in my view I use the collection in this way:

$.each(this.collection.models,function(i,model){
      console.log(model);
})

The problem is, my models are not getting set as the TodoModel type. They are simple Object types. Can someone help me in letting me know where I am going wrong here?

Thank you.

Sushanth --
  • 55,259
  • 9
  • 66
  • 105
Sudo
  • 559
  • 1
  • 8
  • 15

2 Answers2

1

I don't think you are correct. The console.log may say it is an object but it is almost certainly an instance of your Model. Also, if the code in your example is your real code then it is broken because you are using the each function with backwards parameters and you are using Todo where you should be using TodoModel.

this.collection.each(function (model) {
  console.log(model instanceof TodoModel);
});
Andrew Hubbs
  • 9,338
  • 9
  • 48
  • 71
1

I think you just have a typo. model: Todo should be model: TodoModel

Adam Storr
  • 1,438
  • 2
  • 21
  • 46