向 Angular 选择的组合框动态添加选项 [英] Dynamically add options to a Angular chosen combo box

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

问题描述

以下代码不起作用:

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

我从一个 Angular Bootstrap 主题中获取了这个,我正在努力使用它.基本上我想从这个角度脚本中使用

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-repeat 而不是 ng-options,它在前几次尝试中奏效.但现在我不能再重复了,我只有一个空的保管箱.我没有改变任何东西,但它不再起作用.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?

推荐答案

我是这样解决的:

在您的选择标签中,输入 ng-if="trainers".这将阻止 DOM 加载,直到您的 http 请求完成

In your select tag, put ng-if="trainers". This would prevent DOM loading until your http request is completed

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

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