Javascript ReactJS排序列表localCompare在与ID关联的列上抛出erorr

Javascript ReactJS排序列表localCompare在与ID关联的列上抛出erorr,javascript,reactjs,Javascript,Reactjs,我正在编写一个带有排序功能的列的react js表。仅包含文本的列工作正常,但我发现以下错误: TypeError:无法读取未定义的属性“localeCompare” 我假设或猜测localeCompare只对文本列起作用,它会轰炸带有整数的列。对吗 我的排序功能是 SortTable(event, sortKey) { if (!this.state.ascending) { this.state.application.sort((a,b) => a[sort

我正在编写一个带有排序功能的列的react js表。仅包含文本的列工作正常,但我发现以下错误:

TypeError:无法读取未定义的属性“localeCompare”

我假设或猜测localeCompare只对文本列起作用,它会轰炸带有整数的列。对吗

我的排序功能是

SortTable(event, sortKey) {

if (!this.state.ascending) {
            this.state.application.sort((a,b) => a[sortKey].localeCompare(b[sortKey]))
            this.state.ascending = true
         
        } else {
            this.state.application.sort((a,b) => b[sortKey].localeCompare(a[sortKey]))
            this.state.ascending = false    
         
        }
}
我的表格代码如下

<Table striped bordered>
                                        <thead style={{'background-color': 'rgb(248,248,255)'}}>
                                            <tr>
                                <th   onClick={e=> this.sortTable(e,'myId')}>
                                                    <Button s 
                                                    <div>Phase<i className={this.state.iconName}/></div></Button></th>
</tr>
                                        </thead>
                                        <tbody>
                                            <tr>

                <td style={{textAlign:'center'}}>{this.getStringBaseOnId(myId)}</td>
            
             
            </tr>
                                        </tbody>
                                    </Table>

感谢您的帮助。谢谢

看起来您的函数参数有输入错误(
sortyKey
)。是这样吗?您需要检查值是否为null,并使用管道指定为空,您的函数也有参数sortyKey,但您是在检查sortKey
getStringBaseOnId(id) {
  return 'Test'
}