Вопрос

I have backbone collection with several models. I want comma separated string of one attribute of that models exist in this collection. How do I do this? any guess? later on I want filter this collection with specific attribute and then get comma separated string.

example : var collection = Backbone.Collection.extend({ url:'/getsuggestions', model: SomeModel }) 1st model in collection has value like this : SomeModel.set('attr1', '1'); SomeModel.set('attr2', '2'); SomeModel.set('attr3', '3');

2nd model in collection has value like this : SomeModel.set('attr1', '101'); SomeModel.set('attr2', '202'); SomeModel.set('attr3', '303');

above both model exist in collection. Now I want 'attr1' as comma separated string like '1,101'.

thanks

Это было полезно?

Решение

You can use the collection pluck method\

here's an example using :

collection.pluck('attr1').toString()
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top