有什么方法可以通过 javascript 使用 kendo 创建复选框列表
is there any way to create a checkbox list through javascript using kendo
我想知道是否有一种方法可以通过 javascript object/array 编程填充我的 kendo 复选框列表,如下图所示,因为大多数在线搜索结果都在创建html 处的列表。
如果您已经呈现了复选框列表,则使用 MVVM checked 绑定:
http://demos.telerik.com/kendo-ui/mvvm/elements
http://docs.telerik.com/kendo-ui/framework/mvvm/bindings/checked
如果要根据一些数据渲染带有JavaScript的复选框列表,同时勾选复选框,则使用Kendo UI 模板和kendo.render()
http://docs.telerik.com/kendo-ui/framework/templates/overview
http://docs.telerik.com/kendo-ui/api/javascript/kendo#methods-render
<ul id="checkboxList"></ul>
<script>
var template = kendo.template("<li>" +
"<label>" +
"<input type='checkbox' #: isChecked ? \" checked='checked'\" : \"\" # />" +
"#: name #" +
"</label>" +
"</li>");
var data = [
{ id: 1, name: "foo", isChecked: true },
{ id: 2, name: "bar", isChecked: false }
];
var html = kendo.render(template, data);
$("#checkboxList").html(html);
</script>
而不是 kendo.render()
,您可以选择使用 Kendo UI ListView 和项目模板。模板定义本身可以相同。
http://demos.telerik.com/kendo-ui/listview/index
http://docs.telerik.com/kendo-ui/api/javascript/ui/listview#configuration-template
我想知道是否有一种方法可以通过 javascript object/array 编程填充我的 kendo 复选框列表,如下图所示,因为大多数在线搜索结果都在创建html 处的列表。
如果您已经呈现了复选框列表,则使用 MVVM checked 绑定:
http://demos.telerik.com/kendo-ui/mvvm/elements
http://docs.telerik.com/kendo-ui/framework/mvvm/bindings/checked
如果要根据一些数据渲染带有JavaScript的复选框列表,同时勾选复选框,则使用Kendo UI 模板和kendo.render()
http://docs.telerik.com/kendo-ui/framework/templates/overview
http://docs.telerik.com/kendo-ui/api/javascript/kendo#methods-render
<ul id="checkboxList"></ul>
<script>
var template = kendo.template("<li>" +
"<label>" +
"<input type='checkbox' #: isChecked ? \" checked='checked'\" : \"\" # />" +
"#: name #" +
"</label>" +
"</li>");
var data = [
{ id: 1, name: "foo", isChecked: true },
{ id: 2, name: "bar", isChecked: false }
];
var html = kendo.render(template, data);
$("#checkboxList").html(html);
</script>
而不是 kendo.render()
,您可以选择使用 Kendo UI ListView 和项目模板。模板定义本身可以相同。
http://demos.telerik.com/kendo-ui/listview/index
http://docs.telerik.com/kendo-ui/api/javascript/ui/listview#configuration-template