【问题标题】:Kendo MultiSelect update of ngmodelngmodel 的 Kendo MultiSelect 更新
【发布时间】:2015-03-16 14:08:15
【问题描述】:

我正在尝试添加一个按钮,用于向剑道的多选的 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 时,不会向下拉选择占位符添加任何内容。有什么想法吗?

【问题讨论】:

    标签: angularjs kendo-ui angularjs-scope angularjs-ng-model kendo-multiselect


    【解决方案1】:

    你需要在你的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>
    

    Please see this updated plunker example

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-02-09
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多