我正试着把我的商店按百货公司的名称分组。部门名称也包含一些空值。当我尝试与排序函数一起分组时,它的结果是来自同一个名称的多个组。
有关详细信息,请参阅此坐立不安。我不明白我做错了什么。敬请指教。
发布于 2017-05-17 06:45:59
你的sorterFn是错的。
sorterFn必须返回三个不同的值:
1。-1。0。您的sorterFn从不返回0。试试这个:
sorterFn: function(a, b) {
if(a.get('department')=="Management" && b.get('department')=="Management") return 0;
if(a.get('department')=="Management") return 1;
if(b.get('department')=="Management") return -1;
if(a.get('department') < b.get('department')) return 1;
if(a.get('department') > b.get('department')) return -1;
return 0;
},此外,您的transform函数是无用的。它只从您覆盖的原始sorterFn中调用。如果您愿意的话,您必须在您的sorterFn中说明空值。(然而,通常情况下,人们最终会把“其他”这类分类放在最后,而不是在"IT“和”销售“之间。)
此外,要在标题行中写入部门,必须重写groupHeaderTpl模板。
groupHeaderTpl: [
'<tpl if=\'name\'>{name}<tpl else>Others</tpl>'
]https://stackoverflow.com/questions/44016618
复制相似问题