Start a new topic

Backbone usage

Hey,



a small (and hopefully easy) question regarding the Backbone Library of Kinvey.





1. Fetching a specific amount from the data-store

2. On another place in the application i want to access this collection but not fetch it again.





What i thought:

I can use the "map" functionality from Backbone to loop through each element, this doesn't seems to work.



What is the best practise for this? Fetching again with "offline" set to true?





Best,

Nico










Did you try looping over the models property?



collection.fetch(...);



// Later on, loop over the models.

for(var model in collection.models) {

// Do something with the model.

}
Hey,



sure that works :)



But i mean... It's the "backbone" library - shouldn't the backbone methods work there?

I think that searching/looking for an expliciti model by a property is a often use case.





Best, Nico
The `collection.map` method should work as well. What exactly didn’t work?



If I try to run the following script, it logs a line for every model in the collection (without refetching it).



```

var c = new Kinvey.Backbone.Collection([],{ url: 'collection'});

c.fetch().then(function() {

c.map(function(model, index, collection) {

console.log("Model", model);

});

});

```
Login or Signup to post a comment