过滤后将DropDownList重新绑定到值字段

时间:2015-08-27 13:01:07

标签: javascript kendo-ui kendo-datasource kendo-dropdown

过滤然后取消过滤kendo下拉列表后,视图模型会保留最初选择的值,但下拉列表的值为空字符串。

这是下拉列表的预期行为吗?我希望小部件与其模型保持同步。我怎样才能重新打造"下拉列表,所以它在过滤后从其视图模型中获取值?



var viewModel = kendo.observable({
    selectedProduct: null,
    products: [
        { id: 1, name: "Coffee" },
        { id: 2, name: "Tea" },
        { id: 3, name: "Juice" }
    ]
});

kendo.bind($("#dropdown"), viewModel);

var ddl = $("#dropdown").getKendoDropDownList();

console.log("viewModel.selectedProduct.id: " + viewModel.selectedProduct.id + ", ddl.value(): " + ddl.value());

ddl.dataSource.filter({field: "id", value: 4});
ddl.dataSource.filter({});

console.log("viewModel.selectedProduct.id: " + viewModel.selectedProduct.id + ", ddl.value(): " + ddl.value());

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>JS Bin</title>
  <link href="http://cdn.kendostatic.com/2015.2.624/styles/kendo.common.min.css" rel="stylesheet" />  
  <link href="http://cdn.kendostatic.com/2015.2.624/styles/kendo.default.min.css" rel="stylesheet" />  
  <script src="http://code.jquery.com/jquery-1.8.3.min.js"></script>
  <script src="http://cdn.kendostatic.com/2015.2.624/js/kendo.all.min.js"></script>
  
</head>
<body>
<select id="dropdown" data-role="dropdownlist" data-option-label="Select product..."
  data-value-field="id" data-text-field="name" data-bind="value: selectedProduct, source: products">
</select>
<script>

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

1 个答案:

答案 0 :(得分:0)

以下是我能够重新定价的方法。这取决于一些无证的剑道东西,所以我还是更喜欢另一种方式。

-enableLink:FrameworkConf