2

In a youtube tutorial I saw a different way of declaring a model:

model = Backbone.Model({
data:[
    {text:"Google", href:"https://google.com"},
    {text:"Facebook", href:"https://facebook.com"},
    {text:"Youtube", href:"https://youtube.com"}
  ]

});

my console log is throwing error:

Uncaught TypeError: Object # has no method 'set'

Is this the right way to do it?

Keshav Agrawal
  • 577
  • 9
  • 23
  • You need to instantiate `Backbone.Model` with `new`. Also, are you sure you don't mean to use `Backbone.Collection`? You're passing an array of multiple objects... – Will M Oct 07 '13 at 14:27
  • @willM Thanks for pointing out that silly mistake about new. Also I am new to backbone. I am yet to reach collections tutorial ;) I will use that soon. Thanks – Keshav Agrawal Oct 07 '13 at 14:43

1 Answers1

0

try this:

var model = Backbone.Model.extend({
    data:[
        {text:"Google", href:"https://google.com"},
        {text:"Facebook", href:"https://facebook.com"},
        {text:"Youtube", href:"https://youtube.com"}
   ]
});

So, as related here, creating a Bakbone.Model() means the creation of a custom model, and as you appear wanting, to create a Model you need to use Backbone.Model.extend().

Community
  • 1
  • 1
Claudio Santos
  • 1,307
  • 13
  • 22
  • Thanks for pointing out that link which cleared the difference. I was thinking why that tutorial didn't use extend. Now I know. – Keshav Agrawal Oct 07 '13 at 14:41