我有一个javascript对象数组,如下所示:
element = '<mydirective/>';
element = $compile(element)(scope);
我尝试使用过滤功能
过滤掉结果[
{"fname":"tim", "lname":"thompson", "user_id": "2", "route_id": "3", "route_day": "WED"},
{"fname":"john", "lname":"wilson", "user_id": "3", "route_id": "3", "route_day": "WED"},
{"fname":"george", "lname":"lane", "user_id": "5", "route_id": "2", "route_day": "MON"}
]
但每次我这样做,我得到一个空数组。我知道我一定做错了什么,但我无法弄清楚是什么。
编辑:再次对不起我的错误,这次我完成了全部功能。答案 0 :(得分:4)
==
代替=
Route_day
代替route_day
var objArr = [
{"fname":"tim", "lname":"thompson", "user_id": "2", "route_id": "3", "Route_day": "WED"},
{"fname":"john", "lname":"wilson", "user_id": "3", "route_id": "3", "Route_day": "WED"},
{"fname":"george", "lname":"lane", "user_id": "5", "route_id": "2", "Route_day": "MON"}
];
var newobj = objArr.filter(function(ele, ind, arr){
console.log(ele);
return ele.route_id == "3" && ele.Route_day == "WED";
});
console.log(newobj);
&#13;
答案 1 :(得分:-1)
您缺少一个相等的运算符,而您的对象属性名称错误“Route_day”:
var newobj = obj.filter(function(ele, ind, arr){
return ele.route_id === "3" && ele.route_day === "WED";
});
希望这有帮助