假设我有这个功能:
vm.setSelectedItem = function(itemName, searchedItems){
vm.selectedItem = _.findWhere(searchedItems, {name: itemName});
};
我需要让“名字”动态
vm.setSelectedItem = function(itemName, searchedItems, propertyKey){
vm.selectedItem = _.findWhere(searchedItems, {}); //How do I use the arg propertyKey here?
};
我该怎么做?
答案 0 :(得分:2)
尝试:
vm.setSelectedItem = function(itemName, searchedItems, propertyKey){
var obj = {};
obj[propertyKey] = itemName;
vm.selectedItem = _.findWhere(searchedItems, obj);
};
答案 1 :(得分:0)
vm.setSelectedItem = function(itemName, searchedItems, propertyKey)
{
var obj = {};
obj[ propertyKey ] = itemName;
vm.selectedItem = _.findWhere(searchedItems, obj); //How do I use the arg propertyKey here?
};