javascript Backbone.js - 如何从集合中获取对象文字数组?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15868979/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Backbone.js - How to get an array of object literals out of a collection?
提问by professormeowingtons
I'm trying to keep an array of object literals in sync with server data. These objects are being placed on a Google map via backbone.googlemaps extension.
我正在尝试使一组对象文字与服务器数据保持同步。这些对象通过backbone.googlemaps 扩展被放置在谷歌地图上。
I have a collection:
我有一个集合:
var LocationList = Backbone.Collection.extend({ model: Location, url: '/locations' })
var LocationList = Backbone.Collection.extend({ model: Location, url: '/locations' })
How can I grab an array of object literals from this LocationList
collection? My goal is such:
如何从此LocationList
集合中获取一组对象文字?我的目标是这样的:
[{name: "Home", address: "123 Pleasant St"}, {name: "Work", address: "123 Unpleasant St"}]
[{name: "Home", address: "123 Pleasant St"}, {name: "Work", address: "123 Unpleasant St"}]
回答by Cubed Eye
回答by Eru
use underscore.js pluck method: http://underscorejs.org/#pluck
使用 underscore.js pluck 方法:http: //underscorejs.org/#pluck