动态添加选项,以一个角度选择组合框 [英] Dynamically add options to a Angular chosen combo box

查看:199
本文介绍了动态添加选项,以一个角度选择组合框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下code不工作:

<select ui-jq='chosen' ng-model='trainer_list' multiple class="form-control" data-placeholder="Select Multiple Trainers" ng-options='trainer.id as trainer.name for trainer in trainers'>

</select>

我把这个从角度引导主题,我挣扎使用它。基本上,我想从这个角度脚本中使用

I took this from an Angular Bootstrap theme, and I'm struggling to use it. Basically I want to use from this angular script

$http({
        method: 'GET',
        url: 'http://localhost/training_system/retrieve_train.php?trainer=Y'
}).success(function (result) {
    $scope.trainers = result;

});

和组合框中使用它,我不能用静态的选项,这显然是工作的唯一的人。我该怎么办?

and use it in the combo box, i can't use static options, which apparently are the only ones working. what do i do?

更新:所以,我想通过Abhilash解决方案采用NG-重复,而不是NG选项,和它的工作的前几个尝试。但是,现在我再也不能重复它,我只有一个空的Dropbox。我没有改变什么,但它不再工作。难道UI-JQ是AngularJS不兼容?

UPDATE: So I tried the solution by Abhilash using ng-repeat instead of ng-options, and it worked the first few attempts. But now I could no longer repeat it, and all I have is an empty dropbox. I didn't change anything, but it's no longer working. Is it possible that ui-jq is incompatible with AngularJS?

推荐答案

试试这个:

<select ui-jq='chosen' ng-model='trainer_list' multiple class="form-control" data-placeholder="Select Multiple Trainers">
    <option value="{{trainer.id}}" ng-repeat="trainer in trainers"> {{trainer.name}} </option>
</select>

调试您的变量教员

随便找个地方在你的页面添加此code调试,

Just add this code anywhere in your page to debug,

<label> To Do: Remove this after testing. Trainer = {{trainers}} </label>

和看什么都在教练的值。这个变量就是你的服务器调用后更新?

And see what are the values in trainer. Is this variable is updating after your server call?

这篇关于动态添加选项,以一个角度选择组合框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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