私は jQuery とunderscore.jstitle1-2
を使用していますが、アクションを対応させたいと思っています。
this.items = {
menuItems: [
{ title: 'title1',
data: [
{ title: 'title1-1',
action: 'action1-1'
},
{ title: 'title1-2',
action: 'action1-2'
}
]
},
{ title: 'title2',
data: [
{ title: 'title2-1',
action: 'action2-1'
},
{ title: 'title2-2',
action: 'action2-2'
}
]
}
]
};
現在、これを行うには次のコードがあります。
var item = _.find(_.flatten(_.pluck(this.items.menuItems, 'data')), function (item) { return item.title === 'title1-2'; });
console.log(item.action);
それを見つけるより良い方法はありますか?