How to log a certain field of every model in a collection

后端 未结 1 1640
眼角桃花
眼角桃花 2021-01-28 23:37

Hi im trying to output every \"lat\" field from my collection. However anything i do returns the right number of results but they all say undefined, the data is definitely there

相关标签:
1条回答
  • 2021-01-29 00:20

    Ah, so your model attributes data structure is not what everyone thought. Based on your attributes structure, you need something like this. It's a bit fragile due to assuming positionHistory is an array with at least one element, but that's where your data is.

    var ccLocal = window.router.carsCollection;
    _.each(ccLocal.models, function(model) {
       console.log(model.get('positionHistory')[0].lat);
    })
    
    0 讨论(0)
提交回复
热议问题