Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/flutter/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
从A到Z的排序表不正确(javascript)_Javascript_Sorting_Reactjs - Fatal编程技术网

从A到Z的排序表不正确(javascript)

从A到Z的排序表不正确(javascript),javascript,sorting,reactjs,Javascript,Sorting,Reactjs,我使用算法对名字列表进行排序 handleSort(sortColumn, direction){ const comparer = (a, b) => { if(direction === 'ASC'){ return (a[sortColumn] > b[sortColumn]) ? 1 : -1 } else if (direction === 'DESC') {

我使用算法对名字列表进行排序

handleSort(sortColumn, direction){
        const comparer = (a, b) => {
            if(direction === 'ASC'){
                return (a[sortColumn] > b[sortColumn]) ? 1 : -1
            } else if (direction === 'DESC') {
                return (a[sortColumn] < b[sortColumn]) ? 1 : -1
            }
        }
        const rows = direction == '' ? this.state.rows.slice(0) : this.state.rows.sort(comparer);
        this.setState({rows})
    }
从Z到类似于:

school test
hkhkhkh
fff
YMCA CDC @ Zhenghua
YMCA CDC @ Woodlands
YMCA CDC @ Bukit Batok
Sunflower Kinderhub LLP
为什么不分类??比如:

fff
hkhkhkh
school test
Sunflower Kinderhub LLP
YMCA CDC @ Bukit Batok
YMCA CDC @ Woodlands
YMCA CDC @ Zhenghua
对于由1个单词组成的简单名称,工作正常。。如何对由3个单词创建的名称进行排序?

如何使用:

a[sortColumn].localeCompareb[sortColumn]而不是a[sortColumn]>b[sortColumn]

让我们看看我的例子:

var arr=[“Sunflower Kinderhub LLP”, ‘基督教青年会疾控中心@布吉巴托克’, “基督教青年会林地疾控中心”, ‘基督教青年会疾病预防控制中心@正华’, “fff”, “HKH”, “学校考试”];
console.logarr.sorta,b=>a.localeCompareb;仍然排序不正确,`fff,学校考试,基督教青年会疾控中心@Woodlands,基督教青年会疾控中心@Zhenghua基督教青年会疾控中心,@Bukit Batok,Sunflower Kinderhub LLP,HKH`我找到了原因,它先用大写字母排序,然后用小写字母排序
fff
hkhkhkh
school test
Sunflower Kinderhub LLP
YMCA CDC @ Bukit Batok
YMCA CDC @ Woodlands
YMCA CDC @ Zhenghua