mirror of https://github.com/layui/layui
优化 layui.sort 新增一个参数控制是否直接修改数组顺序
parent
edbf24b8ca
commit
6d43db5e22
|
@ -614,12 +614,12 @@
|
||||||
};
|
};
|
||||||
|
|
||||||
// 将数组中的成员对象按照某个 key 的 value 值进行排序
|
// 将数组中的成员对象按照某个 key 的 value 值进行排序
|
||||||
Layui.prototype.sort = function(arr, key, desc){
|
Layui.prototype.sort = function(arr, key, desc, notClone){
|
||||||
var that = this
|
var that = this
|
||||||
,clone = JSON.parse(
|
,clone = notClone ? (arr || []) : JSON.parse(
|
||||||
JSON.stringify(arr || [])
|
JSON.stringify(arr || [])
|
||||||
);
|
);
|
||||||
|
|
||||||
// 若未传入 key,则直接返回原对象
|
// 若未传入 key,则直接返回原对象
|
||||||
if(that.type(arr) === 'object' && !key){
|
if(that.type(arr) === 'object' && !key){
|
||||||
return clone;
|
return clone;
|
||||||
|
|
Loading…
Reference in New Issue