2017-06-25 30 views
0

- http://dotansimha.github.io/angularjs-dropdown-multiselect/ 我面臨的問題是可選屬性沒有被綁定到模型AngularJS下拉多選選項沒有約束力

 <div style="margin: 5%" checkboxes="true" 
    ng-dropdown-multiselect="" options="example1data" selected-model="example1model"></div> 

例如:

如果模型是:

$scope.example1model = []; 

    $scope.example1data = [ {id: 1, label: "David"}, {id: 2, label: "Jhon"}, {id: 3, label: "Danny"} ]; 

問題: 爲選項結合小號似乎並不正常工作,因爲我只得到ID(S)其餘工作正常,如果我檢查大衛和約翰,在選項與$結合scope.example1model只顯示ID標籤 即:[{"id":1},{"id":2} ,但我要的是

[ 
    { 
    "id": 1, 
    "label": "David" 
    }, 
    { 
    "id": 2, 
    "label": "John" 
    } 
] 

回答

0

你可以嘗試像下面。

\t <!DOCTYPE html> 
 
\t <html> 
 
\t <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular.min.js"></script> 
 
\t <body> 
 

 
\t <div ng-app ="sortApp" ng-controller ="mainController"> 
 
\t \t \t \t \t <!DOCTYPE html> 
 
<html lang="eng-US"> 
 
\t <head> 
 
\t \t <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular.min.js"></script> 
 
\t </head> 
 
\t <body> 
 
\t  <select class="multiselect" data-placeholder="Select Products" 
 
     ng-model="example1model" ng-options="item as item.label for item in example1data" 
 
     multiple="multiple" multiselect-dropdown > 
 
    </select> 
 
\t {{example1model}} 
 
\t \t <div style="margin: 5%" checkboxes="true" ng-dropdown-multiselect="" options="example1data" selected-model="example1model"></div> 
 
\t </body> 
 
</html> 
 
\t \t \t \t </div> 
 
\t <script> 
 
\t angular.module('sortApp', []) 
 

 
\t .controller('mainController', function($scope) { 
 
\t $scope.example1model = []; 
 

 
    $scope.example1data = [ {id: 1, label: "David"}, {id: 2, label: "Jhon"}, {id: 3, label: "Danny"} ]; 
 
\t 
 
\t }); 
 
\t </script> 
 

 
\t </body> 
 
\t </html>

0

設置externalIdProp爲空字符串

$scope.extraSettings = { 
    externalIdProp: '' 
    }; 

HTML

<div ng-dropdown-multiselect="" options="options" selected-model="myModel" extra-settings="extraSettings"></div> 

工作對我來說,我使用^1.11.8