我想知道如何在Kendo mobile 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'
我需要在这做什么?如何获取所选项目的索引?欢呼声
答案 0 :(得分: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);
}
});
}