2015-09-10 206 views
2

我希望隨時添加新的值到chosen.js多選。 (吹罰http://harvesthq.github.io/chosen/角度選擇多選動態追加選項不起作用

多選擇工作正常,但我想提供給用戶增添下降的項目下來飛

我一個使用angularjs和MongoDB當我使用bootstarp模型添加一個項目在控制器中的模型得到填充,但它不反映在下拉列表

我是一隻新蜜蜂我明白我想對插件做一些更改,但不知道該怎麼做請幫忙enter image description here

回答

0

我有一個指令叫Angular Chosen使用Angular with selected。 您只需將chosen添加到您的選擇。

var app = angular.module('myApp', ['localytics.directives']); 
 

 
app.controller('MainCtrl', function($scope, $http) { 
 
    $scope.name = 'Multiple Angular Chosen Example using ngModel and ngOptions'; 
 
    $scope.state = [3, 2]; 
 
    
 
    //Static items 
 
    $scope.states = [ 
 
    {id: 1, tite: 'Alaska'}, 
 
    {id: 2, title: 'Arizona'}, 
 
    {id: 3, title: 'Arkansas'}, 
 
    {id: 4, title: 'California'} 
 
    ]; 
 
    
 
    //Remote items 
 
    $http({ 
 
    method: 'get', 
 
    url: 'http://jsonplaceholder.typicode.com/posts' 
 
    }).success(function(posts) { 
 
    console.log(posts); 
 
    $scope.states = posts; 
 
    }); 
 
});
select {width: 400px;}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script> 
 
<script src="//cdnjs.cloudflare.com/ajax/libs/chosen/1.0/chosen.jquery.min.js"></script> 
 
<script src="https://rawgit.com/leocaseiro/angular-chosen/master/dist/angular-chosen.min.js"> 
 
</script> 
 
<link data-require="[email protected]*" data-semver="1.0.0" rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/chosen/1.0/chosen.min.css" /> 
 
    
 

 
<div ng-app="myApp" ng-controller="MainCtrl">  
 
<select chosen multiple ng-model="state" ng-options="s.id as s.title for s in states"> 
 
    <option value=""></option> 
 
</select> 
 
</div>