0

In backbone javascript models, we get individual items as shown below:

var type = this.model.get("type");

Here, type will be defined in server side & then fetched in JS using above syntax.

My question is how do I get the entire model in one shot?

I tried this.model.toString() but it prints [object object]

Any suggestion?

EDIT: I'm using above line of code in backbone view & not the model. And in this view, I need to read all the models data even if its JSON string, thts fine with me. How do I get it. I don't want to use separate collection or anything else. I need to update the above view only to get entire model.

jgillich
  • 71,459
  • 6
  • 57
  • 85
Freephone Panwal
  • 1,547
  • 4
  • 21
  • 39

2 Answers2

1

You can use model.toJSON() to get all the attributes of a model.

go-oleg
  • 19,272
  • 3
  • 43
  • 44
0

you use a collection

http://backbonejs.org/#Collection

You can then iterate though the collection to obtain each model.

var Library = Backbone.Collection.extend({
  model: Book
});

for example and then

books = new Library();
books.each(function(book) {
  book.publish();
});

to iterate

exussum
  • 18,275
  • 8
  • 32
  • 65