저는 jQuery와 underscore.js을 사용하고 있습니다. 나는 title1-2
이며 이에 해당하는 조치를 취하고 싶습니다.이 데이터를 얻는 더 좋은 방법이 있습니까?
var item = _.find(_.flatten(_.pluck(this.items.menuItems, 'data')), function (item) { return item.title === 'title1-2'; });
console.log(item.action);
을 찾을 수있는 더 좋은 방법이 :
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'
}
]
}
]
};
현재, 나는이 작업을 수행하려면 다음과 같은 코드가?
그것은 나에게 상당히 좋게 보입니다. 그러나이 질문은 codereview.stackexchange.com에 더 적합 할 수 있습니다 –
당신의 질문은 무엇입니까? – Sangeeta