Lightning 数据表在尝试使用 onsort 事件时抛出错误

Lightning datatable throws an error when attempting to use onsort event

尝试对闪电数据表进行排序时,弹出错误 'NoErrorObjectAvailable'。

HTML:

       key-field="Id"
       data={jobItems}
       columns={columns}
       hide-checkbox-column
       onrowaction={handleRowAction}
       onsort={updateColumnSorting}
   ></lightning-datatable>```

JS:
updateColumnSorting(event)
{          
   var fieldName = event.detail.fieldName;
   var sortDirection = event.detail.sortDirection;

   console.log('## fieldName: ' + fieldName);
   console.log('## sortDirection: ' + sortDirection);
            
}```

ERROR:

[NoErrorObjectAvailable] 脚本错误。 a()@https://static.lightning.force.com/cs70/auraFW/javascript/7p9HLMpgnV2GO9Mq/aura_prod.js:948:169 {匿名}()@https://static.lightning.force.com/cs70/auraFW/javascript/7p9HLMpgnV2GO9Mq/aura_prod.js:948:362 ln.dispatchEvent()@https://static.lightning.force.com/cs70/auraFW/javascript/7p9HLMpgnV2GO9Mq/aura_prod.js:12:12146 ln.fireSortedColumnChange()@https://COMPANY_NAME--SANDBOX_NAME.lightning.force.com/components/lightning/datatable.js:2:66247 ln.handleUpdateColumnSort()@https://COMPANY_NAME--SANDBOX_NAME.lightning.force.com/components/lightning/datatable.js:2:65875```

我今天在尝试从 lightning-comboboxonchange 处理程序调度自定义事件时遇到了类似的问题。帮助我摆脱错误的是将 var 更改为 const.

不起作用

 handleSearchOptionChange(event) {
      console.log(event.detail, event.detail.value);
      this.selectedBoatTypeId = event.detail.value;

      var searchEvent = new CustomEvent('search', { detail:{ boatTypeId: event.detail.value }});
      this.dispatchEvent(searchEvent);
 }

工作

 handleSearchOptionChange(event) {
      console.log(event.detail, event.detail.value);
      this.selectedBoatTypeId = event.detail.value;

      const searchEvent = new CustomEvent('search', { detail:{ boatTypeId: event.detail.value }});
      this.dispatchEvent(searchEvent);
 }

不确定在您的特定情况下是否相同,但想分享它,因为它花费了我大约 45 分钟的调试时间...

发现问题。错误是在 VS Code 中错误地将排序函数放在另一个函数中。通过适当的突出显示和所有内容,它保存得很好。当我试图在它后面写一个 getter 函数时它才出错。