mirror of
https://github.com/flarum/framework.git
synced 2024-12-15 08:33:38 +08:00
Improve ordering of list items when specified key doesn't exist
This commit is contained in:
parent
cc6113243a
commit
f667313cc2
|
@ -41,21 +41,17 @@ export default class ItemList {
|
||||||
addItems('push', false);
|
addItems('push', false);
|
||||||
addItems('push', 'last');
|
addItems('push', 'last');
|
||||||
|
|
||||||
items = items.filter(function(item) {
|
items.forEach(item => {
|
||||||
var key = item.position.before || item.position.after;
|
var key = item.position.before || item.position.after;
|
||||||
var type = item.position.before ? 'before' : 'after';
|
var type = item.position.before ? 'before' : 'after';
|
||||||
if (key) {
|
if (key) {
|
||||||
var index = array.indexOf(this[key]);
|
var index = array.indexOf(this[key]);
|
||||||
if (index === -1) {
|
if (index === -1) {
|
||||||
console.log("Can't find item with key '"+key+"' to insert "+type+", inserting at end instead");
|
index = type === 'before' ? 0 : array.length;
|
||||||
return true;
|
|
||||||
} else {
|
|
||||||
array.splice(array.indexOf(this[key]) + (type === 'after' ? 1 : 0), 0, item);
|
|
||||||
}
|
}
|
||||||
|
array.splice(index + (type === 'after' ? 1 : 0), 0, item);
|
||||||
}
|
}
|
||||||
}.bind(this));
|
});
|
||||||
|
|
||||||
array = array.concat(items);
|
|
||||||
|
|
||||||
return array.map((item) => item.content);
|
return array.map((item) => item.content);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user