要拥有三个依赖的组合框,最好使用剑道组合框的“cascadeFrom”属性。一个简单的例子:
<div>
<input id="category" />
<input id="sports" />
<input id="player" />
</div>
<script>
$("#category").kendoComboBox({
dataTextField: "categoryName",
dataValueField: "categoryId",
dataSource: [
{ categoryName: "Sports", categoryId: 1 },
{ categoryName: "Music", categoryId: 2 }
]
});
$("#sports").kendoComboBox({
cascadeFrom: "category",
dataTextField: "sportsName",
dataValueField: "sportsId",
dataSource: [
{ sportsName: "Football", sportsId: 1, categoryId: 1 },
{ sportsName: "Cricket", sportsId: 2, categoryId: 1 },
{ sportsName: "Pop", sportsId: 3, categoryId: 2 },
{ sportsName: "Rock", sportsId: 4, categoryId: 2 }
]
});
$("#player").kendoComboBox({
cascadeFrom: "sports",
dataTextField: "playerName",
dataValueField: "playerId",
dataSource: [
{ playerName: "David Beckham", playerId: 1, sportsId: 1 },
{ playerName: "Leonel Messi", playerId: 2, sportsId: 1 },
{ playerName: "Xavi", playerId: 3, sportsId: 1 },
{ playerName: "Raina", playerId: 4, sportsId: 2 },
{ playerName: "Gambhir", playerId: 4, sportsId: 2 },
{ playerName: "YXZ", playerId: 4, sportsId: 3 },
{ playerName: "ABC", playerId: 4, sportsId: 3 }
]
});
// To set value in combo-box
$("#category").data('kendoComboBox').value(1);
$("#sports").data('kendoComboBox').value(1);
$("#player").data('kendoComboBox').value(2);
</script>
在这里,我已经硬编码了要在组合框中设置的值。您可以从数据库中提取数据并在此处设置。保存组合框的值字段并使用它来显示数据是很好的。
希望这可以帮助。
参考链接