4

我正在尝试添加一个按钮来为剑道的多选的 ngmodel 添加值:

<div ng-controller="MyCtrl">
  <select id='my' kendo-multi-select k-options="selectOptions" k-ng-model="selectedIds"></select>
  <p ng-show="selectedIds.length">Selected: {{ selectedIds }}</p>
  <button ng-click="addSelectedId()">Add selected id</button>
  <input ng-model="enteredId" />
</div>

这里是控制器

  function MyCtrl($scope) {
      $scope.selectOptions = {
          placeholder: "Select products...",
          dataTextField: "ProductName",
          dataValueField: "ProductID",
          autoBind: false,
          dataSource: {
              type: "odata",
              serverFiltering: true,
              transport: {
                  read: {
                      url: "http://demos.telerik.com/kendo-ui/service/Northwind.svc/Products",
                  }
              }
          }
      };
      $scope.selectedIds = [ 4, 7];
       $scope.addSelectedId = function() {
          $scope.selectedIds.push(parseInt($scope.enteredId));
          console.log($scope.selectedIds);
       };
  }

Plunker在这里:

http://plnkr.co/edit/EH0EaMhFsV2JTdwpkqGg?p=preview

添加到 selectedIds 时,不会向下拉选择占位符添加任何内容。有任何想法吗?

4

1 回答 1

3

您需要在 html 代码中添加 k-rebind="selectedIds"

HTML:

<div ng-controller="MyCtrl">
  <select id='my' kendo-multi-select k-options="selectOptions" k-ng-model="selectedIds" k-rebind="selectedIds"></select>
  <p ng-show="selectedIds.length">Selected: {{ selectedIds }}</p>
  <button ng-click="addSelectedId()">Add selected id</button>
  <input ng-model="enteredId" />
</div>

请参阅此更新的 plunker 示例

于 2015-08-26T09:43:59.427 回答