I am trying to use _.where to look through this large json mapping file. I have used it before but the search terms never contained spaces and the function worked well. Now I am using search terms that have spaces and it never brings back any matches. Here is a segment of code with an example entityName (the search term).
entityName = "HEMTT WRECKER M984A1 MK19";
alert("entityName2: " + entityName);
entityMap = _.where(cdpeConfig.oobEntityMap, { "obs name" :entityName});
alert("entityMap: " + entityMap);
Inside of the oobEntityMap there are json elements the above entityName should match with the following:
{
"obs name":"HEMTT WRECKER M984A1 MK19",
"edcss name":"M977_HEMTT_CARGO",
"mapping type":"skos:relatedMatch",
"obs dis enum":"1:2:225:7:19:3:2",
"edcss dis enum":"1:0:225:9:19:1:0"
}
Javascript does not have a _.where() function. Underscore does have this function, which is probably what your using.
http://underscorejs.org/#where
It does allow for spaces.
var stuff = [
{"Bilbo Baggins" : "Little Hobbit"},
{"Gandalf Grey" : "Tall Wizard"}
];
var foo = _.where(stuff, {"Bilbo Baggins" : "Little Hobbit"});
console.log(foo);
Try seeing if cdpeConfig.oobEntityMap that your passing is actually an object or an array and that is not undefined or empty. .
You could try using _.filter
instead of _.where
, to see if that makes any difference:
entityMap = _.filter(cdpeConfig.oobEntityMap, function(obj){
return obj["obs name"].match(/HEMTT WRECKER M984A1 MK19/);
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.