获取绑定到Kendo ListView中的项目的对象 [英] Get the object bound to item in Kendo ListView

查看:131
本文介绍了获取绑定到Kendo ListView中的项目的对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个kendoListView,它绑定到具有多个字段的对象列表.

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)
    {

    }
});

现在的问题是,我找不到一种将整个对象绑定到此输入的方法,即,我希望将整个对象绑定到此选中的输入,这不仅包括名称,还包括EmpID和age(所有属性绑定对象的对象.)

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).

如何实现?是否可以在Kendo列表视图中将对象绑定到项目?

How can this be achieved ?Is it possible to get the object bound to the item in Kendo list view ?

推荐答案

使用 dataItem 方法,并传递与该项相对应的父级div元素.

$("#lstAllItems input").each(function () { 
    if (this.checked)
    {
        var listView = $("#lstAllItems").data("kendoListView");
        var listViewItem = listView.dataItem($(this).closest("div"));
    }
});

listViewItem将是 Kendo UI模型对象.

这篇关于获取绑定到Kendo ListView中的项目的对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆