【发布时间】:2016-02-26 12:13:22
【问题描述】:
我用 lodash 编写了这个函数,但有时它可以正常工作而其他人则不行,它写得很好还是我的语法有误?
myApp.controller('geoCtrl', function($scope, Canchas){
var filtro = [];
$scope.filtroJugadores = function(){
if($scope.j5===true){
var j5 = _(filtro).push({'jugadores5':true});
j5 = j5.commit();
}else{
_.dropWhile(filtro, ['jugadores5', true]);
//index = _.indexOf(filtro, _.find(filtro, {'jugadores5':true}));
//if (index != -1){filtro.splice(index, 1, {'jugadores5':false})};
}
if($scope.j9===true){
var j9 = _(filtro).push({'jugadores9':true});
j9 = j9.commit();
}else{
_.dropWhile(filtro, ['jugadores9', true]);
//index = _.indexOf(filtro, _.find(filtro, {'jugadores9':true}));
//if (index != -1){filtro.splice(index, 1, {'jugadores9':false})};
}
filtro = _.uniqBy(filtro, 'jugadores5');
filtro = _.uniqBy(filtro, 'jugadores9');
console.log(filtro);
}
});
【问题讨论】:
-
你能说得更具体点吗?
-
当你点击一个复选框 filtroJugadores 调用函数。如果为真,请在数组中插入对象 { 'jugador5' : true} ,如果为假,则必须将其删除。如果我使用多个复选框,出现故障,或者它没有删除对象,或者我将其保留为 true