gpt4 book ai didi

angularjs - Kendo MultiSelect ngmodel 更新

转载 作者:行者123 更新时间:2023-12-01 16:15:04 26 4
gpt4 key购买 nike

我正在尝试添加一个按钮,用于向 kendo 的多选的 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>

这是 Controller

  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 时,不会向下拉选择占位符添加任何内容。有什么想法吗?

最佳答案

您需要在 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

关于angularjs - Kendo MultiSelect ngmodel 更新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29078883/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com