dtwk6019 2017-06-01 17:08
浏览 60

删除angularjs下拉列表中的未定义值

I am using angularjs(ng-options) to create a select dropdown that is populated using a sql query in php to return my list of options as json.

This works great for 1 dropdown..I am now trying to add a second dropdown that uses a different query. I use php array_merge to merge the 2 query result arrays, then json_encode the merged array.

Both dropdowns populate, but both have a lot of unwanted undefined values and I am not sure why..The undefined values do not exist when I only return 1 singular array (rather than merging the two)

I don't have any undefined result objects in the json itself. Only in the select dropdown

 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>  

</div>
  • 写回答

1条回答 默认 最新

  • doumicheng6732 2017-06-01 18:17
    关注

    Ended up fixing my issue by adding a filter to my ng-options to remove undefined values

    <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>  

    </div>
    
    评论

报告相同问题?

悬赏问题

  • ¥15 虚拟机打包apk出现错误
  • ¥30 最小化遗憾贪心算法上界
  • ¥15 用visual studi code完成html页面
  • ¥15 聚类分析或者python进行数据分析
  • ¥15 逻辑谓词和消解原理的运用
  • ¥15 三菱伺服电机按启动按钮有使能但不动作
  • ¥15 js,页面2返回页面1时定位进入的设备
  • ¥50 导入文件到网吧的电脑并且在重启之后不会被恢复
  • ¥15 (希望可以解决问题)ma和mb文件无法正常打开,打开后是空白,但是有正常内存占用,但可以在打开Maya应用程序后打开场景ma和mb格式。
  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝