fix node index displacement by null/undefined nodes
This commit is contained in:
parent
f589a33842
commit
a425bbca88
10 changed files with 56 additions and 20 deletions
|
|
@ -48,18 +48,18 @@ Mithril = m = new function app(window) {
|
|||
|
||||
if (dataType == "[object Array]") {
|
||||
var nodes = [], intact = cached.length === data.length, subArrayCount = 0
|
||||
for (var i = 0; i < data.length; i++) {
|
||||
var item = build(parent, data[i], cached[i], shouldReattach, index + subArrayCount || subArrayCount, namespace)
|
||||
for (var i = 0, cacheCount = 0; i < data.length; i++) {
|
||||
var item = build(parent, data[i], cached[cacheCount], shouldReattach, index + subArrayCount || subArrayCount, namespace)
|
||||
if (item === undefined) continue
|
||||
if (!item.nodes.intact) intact = false
|
||||
subArrayCount += item instanceof Array ? item.length : 1
|
||||
cached[i] = item
|
||||
cached[cacheCount++] = item
|
||||
}
|
||||
if (!intact) {
|
||||
for (var i = 0; i < data.length; i++) if (cached[i] !== undefined) nodes = nodes.concat(cached[i].nodes)
|
||||
for (var i = nodes.length, node; node = cached.nodes[i]; i++) if (node.parentNode !== null) node.parentNode.removeChild(node)
|
||||
for (var i = cached.nodes.length, node; node = nodes[i]; i++) if (node.parentNode === null) parent.appendChild(node)
|
||||
cached.length = data.length
|
||||
if (data.length < cached.length) cached.length = data.length
|
||||
cached.nodes = nodes
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue