Controller :
app.controller('searchCtrl', function($scope,$rootScope,$http,$q){
$scope.search = function( values , type) {
if($scope.abort) {
$scope.abort.resolve();
}
$scope.abort = $q.defer();
var data={};
data.values=values;
data.type=type;
$http.post("search.php", data,{timeout:$scope.abort.promise}).then(function success (response) {
$rootScope.search_result=response.data;
},function error (response){
console.log("Request cancelled");
}
);
};
});
但我想检查列表中的一个数组项是否具有属性 val!="";除了像
这样的循环之外,还有什么方法可以检查它吗?var flag=0;
for(var i=0; i<values.length; i++){
if(values[i].val!="") flag=1;
}
if(flag)$http...
?
最佳答案
检查 find方法
var flag = data.values.find(function(element){
return element.val != ''
})
if(flag)$http...
关于javascript - angularjs 在请求前检查数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44653469/