我是 Underscore js 的新手,对如何使用它有点困惑。我有一组“目标”,我想通过 ID 找到其中一个。
这是数据:
{"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"
}
...
]}
这就是我正在尝试的,我想获取整个数组/对象,以便我可以获取它的每个字段:
var goalId = 1;
_.each(result.goal, function(item){
_.find(result.goal, function(i){
return i = goalId;
});
});
知道怎么做吗?