删除AngularJS下拉中的未定义值



我正在使用angularjs(ng-options(创建一个选择的下拉列表,该下拉列表使用PHP中的SQL查询填充,以返回我的选项列表,为JSON。

这非常适合1个下拉菜单..我现在正在尝试添加第二个使用不同查询的下拉列表。我使用php array_merge合并2个查询结果数组,然后json_encode合并的数组。

两个下拉列表都填充,但都有很多不必要的不确定值,我不确定为什么。

我在JSON本身中没有任何未定义的结果对象。仅在选择下拉

 getInfo();
function getInfo(){
// Sending request to EmpDetails.php files 
$http.post('databaseFiles/options.php').success(function(result){
// Stored the returned data into scope 
$scope.options = result;
console.log(result);
});
}
<select class="form-control" ng-model="selectedDepartment" 
        ng-options="option.id as option.department for option in options ">
    <option value="">Select Department</option>
</select>  

最终通过在我的ng-options中添加过滤器来删除未定义的值

来解决我的问题

<select class="form-control" ng-model="selectedDepartment" 
        ng-options="option.id as option.department for option in options  **| filter : { id : '!!' }** " >
    <option value="">Select Department</option>
</select>  

最新更新