AngularJS Dropdown Multiselect选项不绑定

时间:2017-06-25 07:34:25

标签: angularjs multi-select

我正在使用AngularJS Dropdown Multiselect - http://dotansimha.github.io/angularjs-dropdown-multiselect/ 我面临的问题是没有绑定到模型的选项属性

        <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)其余工作正常,如果我查看David和John,选项与$ scope.example1model的绑定仅显示 ID 而不是标签 即:[{"id":1},{"id":2} 但我想要的是

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

2 个答案:

答案 0 :(得分:3)

externalIdProp设为空字符串

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

HTML

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

适合我,我正在使用^1.11.8

答案 1 :(得分:0)

你可以尝试如下。

&#13;
&#13;
	<!DOCTYPE html>
	<html>
	<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular.min.js"></script>
	<body>

	<div ng-app ="sortApp" ng-controller ="mainController">
					<!DOCTYPE html>
<html lang="eng-US">
	<head>
		<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular.min.js"></script>
	</head>
	<body>
	    <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>
	 {{example1model}}
		 <div style="margin: 5%" checkboxes="true" ng-dropdown-multiselect="" options="example1data" selected-model="example1model"></div>
	</body>
</html>
				</div>
	<script>
	angular.module('sortApp', [])

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

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

	</body>
	</html>
&#13;
&#13;
&#13;