我正在使用 riotjs 库,并且有两个标签“comment-list”和“comment”。
评论列表:
<comment-list>
<div each={com in comments} >
<comment level={opts.level} comment={com} type={opts.level == 0 ? "parent" : "child"} ctype={commentType}></comment>
</div>
<div show={opts.level == 0}>
<a id="load-trigger" onclick={fetchMore}>Moar comments</a>
</div>
var self = this;
self.commentType = (self.opts.level === 0 ? "parent" : "child");
</comment-list>
并评论:
<comment>
... some html ...
<div class="row" if={opts.level == 0}>
<div class="col s11 offset-s1 m11 offset-m1 l11 offset-l1" style="padding-left: 0;">
<comment-list level={1} fetchMore={fetchMore}></comment-list>
</div>
</div>
</comment>
comment-list.tag初始化为 level = 0。它应该将此 level 值传递给comment.tag。问题是当我尝试在comment.tag中访问opts.level时,我得到“未定义”。ctype也是如此。type始终是“child”,就好像comment-list.tag中的 opts.level没有定义一样。
Ps:我不认为这可能是因为注释列表中的 0 被视为 null 或“未定义”,因为我具有与值 1 相同的行为,例如我是否做错了直接从 opts 对象传递值?