首页 > 解决方案 > Kendo Grid:列模板单击事件在参数列表后抛出 Uncaught SyntaxError:missing )?

问题描述

我有一个带有列模板单击事件的剑道网格。但是在单击单元格时,它会引发以下错误。

Uncaught SyntaxError: missing ) after argument list

以下是我的专栏模板。

columns: [
    {
      field: 'name',
      title: 'Industry',
      headerTemplate: '<span>Industry</span><br><span style="font-size: 10px; font-weight: 400;">2-digit Code</span>',
      width: '40%',
      template: '<div style="text-decoration: underline" onClick=\'logElement(#= name #)\'>#= name#</div>'
      //template: function (dataItem) {
      //  return '<span style="text-decoration: underline">' + dataItem.name + '</span>';
      //}
    }

谷歌搜索说它可能是语法错误,https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Errors/Missing_parenthesis_after_argument_list

但是我在上面的模板中找不到我没有逃脱的东西。

谁能帮帮我?

标签: javascriptonclickkendo-grid

解决方案


谷歌是对的:这是一个语法错误。您正在尝试向函数提交名称logElement。让我猜猜:name是字符串吗?在这种情况下,您必须将值放在引号中。这应该有效:

columns: [
  {
    field: 'name',
    title: 'Industry',
    headerTemplate: '<span>Industry</span><br><span style="font-size: 10px; font-weight: 400;">2-digit Code</span>',
    width: '40%',
    template: '<div style="text-decoration: underline" onClick="logElement(\\"#= name #\\")">#= name#</div>'
    //template: function (dataItem) {
    //  return '<span style="text-decoration: underline">' + dataItem.name + '</span>';
    //}
  }

推荐阅读