I have a standard backbone collection that I am working with.
(function($){
var DataModel = Backbone.Model.extend({});
var DataCollection = Backbone.Collection.extend({
model: DataModel,
url: 'assets/path_data.json'
});
var dataCollection = new DataCollection()
dataCollection.fetch({
reset:true
});
// Choice Model
var ChoiceModel = Backbone.Model.extend({});
var choiceModel = new ChoiceModel({
froms: 'froms',
tos: 'tos'
})
I am attempting to perform an operation on JSON objects that meet specific criteria, but I am encountering two issues with my current code.
for(var i=0, len=choiceModel.length; i<len; i++){
if (choiceModel[i].froms == a){
function geolines (a,b,f,g,h,j){
};
}
}
The variable 'len' is only counting as 2 for the two JSON keys in the Model. How can I adjust this to reflect the actual number of JSON objects in the collection?
I believe my if statement is not correct. I have tried different methods like $.each, $.map and $.grep to access JSON keys in JS, but they are not returning the desired results. What is the best way to iterate through all JSON values associated with the Key 'froms' and check if they match a given variable 'a'?
Thank you for your help!