【发布时间】:2016-03-24 16:48:02
【问题描述】:
我在 vue js 中有一个嵌套的 for ... in 循环。如果元素的值为null,我想要跳过元素。这是html代码:
<ul>
<li v-for="item in items" track-by="id">
<ol>
<li v-for="child in item.children" track-by="id"></li>
</ol>
</li>
</ul>
null 元素可能同时出现在 item 和 item.children 对象中。
例如:
var data = {
1: {
id: 1,
title: "This should be rendered",
children: {
100: {
id: 100,
subtitle: "I am a child"
},
101: null
}
},
2: null,
3: {
id: 3,
title: "Should should be rendered as well",
children: {}
}
};
不应渲染此数据data[1].children[101],如果稍后data[1].children[100] 变为空,则应从列表中将其省略。
附:我知道这可能不是表示数据的最佳方式,但我对此不承担任何责任:)
【问题讨论】:
标签: vue.js