我有一个对象“obj”,其数值为“count”。我想在页面上添加“'计数'”星号图像。像这样的东西:
{{#for i=0;i<count;++i}}
<img src="/star.png" style="width: 16px; height: 16px" />
{{/for}}
我知道这是无效的,但我怎样才能获得这种行为?
最佳答案
我认为您需要扩展 Blaze 对象 Blaze.For
但我不认为你可以评估i<count
和 i++
.
通过扩展 Blaze 的可能实现:
{{#range 0 count 1}}
{{/range}}
懒人实现:
Template.yourTemplate.helpers({
range : function( start , end , inc ){
return _.range( start , end , inc );
}
})
仍然懒惰:
{{#with range 0 count 1}}
{{/with}}
如果您想要 Blaze 的射程功能,您需要处理很多事情。
关于javascript - meteor :带计数器的循环,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29612981/