我一直在尝试让模板内容(ItemTemplate 等)在 MultiSelect 控件中工作。在高层次上,我想在页面加载时加载 MultiSelect 并且我希望能够更新它。
我有一些非常简单的html:
<script type="text/x-kendo-template" id="members-template">
<select multiple="multiple">
# for (var j = 0; j < Members.length; j++) { #
<option selected value=' + Members.length + '>'HI'</option>
# } #
</select>
</script>
<div id="TeeOffTimes"></div>
而javascript是:
var memberData =[
{
"Id": 1,
"FirstName": "Lorenzo",
"LastName": "Lamas",
"Gender": "M",
"Handicap": 72,
"Discount": 0,
"CartId": null,
"Email": null,
"Cart": null,
"Lockers": [],
"MemberAddresses": [],
"MemberCarts": [],
"MemberLockers": [],
"MemberTeeOffs": []
},
{
"Id": 2,
"FirstName": "Harry",
"LastName": "Burgess",
"Gender": "M",
"Handicap": 68,
"Discount": 0,
"CartId": null,
"Email": null,
"Cart": null,
"Lockers": [],
"MemberAddresses": [],
"MemberCarts": [],
"MemberLockers": [],
"MemberTeeOffs": []
},
{
"Id": 3,
"FirstName": "Paul",
"LastName": "Stevens",
"Gender": "M",
"Handicap": 78,
"Discount": 0,
"CartId": null,
"Email": null,
"Cart": null,
"Lockers": [],
"MemberAddresses": [],
"MemberCarts": [],
"MemberLockers": [],
"MemberTeeOffs": []
},
{
"Id": 4,
"FirstName": "Ben",
"LastName": "Crossen",
"Gender": "M",
"Handicap": 82,
"Discount": 0,
"CartId": null,
"Email": null,
"Cart": null,
"Lockers": [],
"MemberAddresses": [],
"MemberCarts": [],
"MemberLockers": [],
"MemberTeeOffs": []
}
];
$(function () {
$('#TeeOffTimes').kendoMultiSelect({
placeholder: "Select members...",
autoBind: false,
dataSource: {
type: "json",
serverFiltering: true,
transport: {
read: {
url: '/echo/json/',
type: 'GET'
}
},
schema: {
parse: function (response) {
var dataForTemplate = { Members: JSON.stringify(memberData) };
return { json: dataForTemplate };
}
}
},
itemTemplate: $("#members-template").html()
}).data("kendoMultiSelect");
});
这是该代码的 jsFiddle。您可以看到我使用了jsFiddle 的echo功能来模拟一个返回相关数据的 Ajax 调用。
有没有准备挑战的剑道忍者?