ng选项初始值选择 [英] ng option initial value select

查看:51
本文介绍了ng选项初始值选择的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个动态组合框.我想初始化所有组合框的值,如下图所示,是通过添加静态值

I have a dynamic combo box. I want to initialise the value of all combo boxes like this the image below is from adding static values like this

  $scope.newObject ={  0 : "N/P" ,1 : "N/P",2 : "N/P",3 : "N/P"}

所以我尝试在下面的代码中对列表中的每个项目进行补偿:

so I tried to make for on each item on the list in this code below:

$scope.inifonction = ["N/P","N/A","OK","KO"];
//this is the option inside the combobox
$scope.displaydata = function(index) {

    $scope.id = index;

    $http.get("/fonctions?id=" + $scope.id).success(function(data) {
        $scope.list = data;

        for(i=0;i<$scope.list.length;i++)
        {
            $scope.tab = $scope.list[i].idfonction
            //this to get the id of the list in a tab 


            console.log($scope.tab)

        //[1,6,5,3] exemple of data in the console 

        $scope.newObject ={  tab : "N/P"}
        }
    });

但是我没有工作,它看起来像这样:

but I didn't work and it looked like this:

这是我的HTML

 <select  ng-model="newObject[l.idfonction]"  ng-options="  fct for fct in inifonction "  class="form-control">

当我插入数据时,由于该ng-model导致此问题

when I insert the data am getting this as a result of that ng-model

Object {1: "N/A", 2: "OK", 3: "N/A", 4: "N/P", tab: "N/P"}

推荐答案

此问题已解决,希望对您有帮助

this fixed my issue i hope it helps you all

<select ng-init="newObject[l.idfonction] = inifonction[0] " ng-model="newObject[l.idfonction]"  ng-options="  fct for fct in inifonction "  class="form-control">

这篇关于ng选项初始值选择的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆