私はUnderscore jsを初めて使用し、その使用方法について少し混乱しています。「目標」のコレクションがあり、そのうちの 1 つを 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;
});
});
それを行う方法はありますか?