问题
I have a kendoListView which is bound to a list of objects having a number of fields.
<div id="lstAllItems"></div>
<script type="text/x-kendo-tmpl" id="itemTemplate">
<div>
<label><input type="checkbox"/>#: Name#</label>
</div>
</script>
<script>
var itemsList = [{Name : "ABC", Age : 23, EmpID : 1},
{Name : "PQR", Age : 25, EmpID : 2},
{Name : "XYZ", Age : 23, EmpID : 3}
];
var _dataSource = new kendo.data.DataSource({
data: itemsList
});
$("#lstAllItems").kendoListView({
dataSource: _dataSource,
template: kendo.template($("#itemTemplate").html())
});
</script>
Now I want to get all the checked items in that list. I have been able to do so using the following code:
$("#lstAllItems input").each(function () {
if (this.checked)
{
}
});
Now problem is that I cannot find a way to get the entire object bound to this input i.e I wish to get the entire object bound to this checked input which not only includes Name but also EmpID and age as well( all the properties of that bound object).
How can this be achieved ?Is it possible to get the object bound to the item in Kendo list view ?
回答1:
Use the dataItem method of the ListView and pass the parent div
element, which corresponds to the item.
$("#lstAllItems input").each(function () {
if (this.checked)
{
var listView = $("#lstAllItems").data("kendoListView");
var listViewItem = listView.dataItem($(this).closest("div"));
}
});
listViewItem
will be a Kendo UI Model object.
来源:https://stackoverflow.com/questions/40822732/get-the-object-bound-to-item-in-kendo-listview