【发布时间】:2018-09-14 06:48:42
【问题描述】:
我在 Kendo Grid 中使用 K 按钮。为了给每一行着色,我应该使用 rowTemplate 和 altRowTemplate 选项。唯一的问题是点击功能没有正确绑定到按钮。
我收到以下错误,
(index):1 Uncaught ReferenceError: viewProfile is not defined 在 HTMLButtonElement.onclick ((index):1)
代码在这里,
myGridOptions({
columns: [
{ field: 'name', title: 'Name', width: '160px'},
{ field: 'address', title: 'address'},
{ field: 'occupation', title: 'Occupation' },
{ field: 'location', title: 'Location'},
{ field: 'salary', title: 'Salary' },
{ field: 'company', title: 'Company'},
{ field: 'phone', title: 'Phone'},
//{ field: 'button', title: ' ' }
{ command: { text: 'View Profile', click: viewProfile }, title: ' ', width: '160px' }
],
dataSource: OccData,
rowTemplate: '<tr style="background-color: rgb(246,246,246)" data-uid="#= uid #">'+
'<td>#: name # </td>' +
'<td>#: address #</td>' +
'<td>#: occupation #</td>' +
'<td>#: location #</td>' +
'<td>#: salary #</td>' +
'<td>#: company #</td>' +
'<td> #: phone#</td>' +
'<td>#: education #</td>' +
'<td><button class="k-button" onclick="viewProfile();">View Profile</button></td>'+
'</tr>',
altRowTemplate: '<tr style="background-color: rgb(255,255,255)" data-uid="#= uid #">'+
'<td>#: name # </td>' +
'<td>#: address #</td>' +
'<td>#: occupation #</td>' +
'<td>#: location #</td>' +
'<td>#: salary #</td>' +
'<td>#: company #</td>' +
'<td> #: phone#</td>' +
'<td>#: education #</td>' +
'<td><button class="k-button" onclick="viewProfile();">View Profile</button></td>'+
'</tr>',
overflow: false
});
我参考了几个链接,但在 rowTemplate 中找不到使用点击功能的解决方案。
剑道开发者的任何建议!!对我有帮助。
【问题讨论】:
标签: javascript kendo-ui kendo-grid