2

我想知道如何在 Kendo 移动 ListView 中获取所选项目的索引。这是我的代码

function loadInformation(){
$('#Template').kendoMobileListView({        
    dataSource: Info,
    template: '<table  style="width: 100%"><tr><td><p>${a = (typeof data.ServiceLocationCompanyName !== "undefined") ? data.ServiceLocationCompanyName : data.LastName + ", " + data.FirstName}</td><td style="width: 84px"><img src=${data.Icon} /></td></tr></table>',

    // Added this event to capture the index of selected Item but was unsuccessful
    click: function(){
    var index = this.select().index(),
    console.log(index);        
    }
});

当我运行它时,它给了我一个错误说

TypeError: Object [object Object] has no method 'select'

我需要在这里做什么?如何获取所选项目的索引?干杯

4

1 回答 1

5

试试这个:

function loadInformation(){
    $('#Template').kendoMobileListView({        
        dataSource: Info,
        template: '<table  style="width: 100%"><tr><td><p>${a = (typeof data.ServiceLocationCompanyName !== "undefined") ? data.ServiceLocationCompanyName : data.LastName + ", " + data.FirstName}</td><td style="width: 84px"><img src=${data.Icon} /></td></tr></table>',

        // Added this event to capture the index of selected Item but was unsuccessful
        click: function(e){
           var index = $(e.item).index();
           var text = $(e.item).text();
           console.log('selected item contains text: ',text,' and its index is: ',index);        
        }
    });
}
于 2012-09-11T21:19:44.337 回答