I'm new to Underscore js and bit confused on how to use it. I have a collection of 'goals' and I want to find one of it by ID.
here's the data:
{"goal":[
{
"category" : "education",
"title" : "Charlie University",
"description" : "Lorem ipsum dolor sit amet",
"date" : "01/03/2020",
"value" : 50000,
"achievability" : 3,
"experimental_achievability": 3,
"suggested": false,
"accounts": [
{
...
},
{
...
}
],
"articles": [
{
...
},
{
...
},
{
...
}
],
"related_goals": [
{
...
}
],
"id":"1"
},
{
"category" : "family",
"title" : "Getting married",
"description" : "Lorem ipsum dolor sit amet",
"date" : "01/03/2022",
"value" : 10000,
"achievability" : 3,
"experimental_achievability": 2,
"suggested": true,
"accounts": [
{
...
}
],
"articles": [
{
...
},
{
...
},
{
...
}
],
"related_goals": [
{
...
}
],
"id":"2"
}
...
]}
That's what I'm trying, I want to get the entire array/object so I can get each field of it:
var goalId = 1;
_.each(result.goal, function(item){
_.find(result.goal, function(i){
return i = goalId;
});
});
Any idea how to do it?
See Question&Answers more detail:os