我有一个“集合”(扩展的事件对象),该对象的数据键中有一个“集合”的键路径,该对象是一个记录数组。
View 使用{{#each collection:i}}
循环集合。并为每条记录的名称生成一个 href。
当用户单击集合项上的链接时,会触发一个事件,该事件会设置“selectedIndex”属性 obj.set('selectedIndex',i)
在我看来,我该如何访问集合中该索引处的记录?
<input type="text" name="title" value="{{abc}}" placeholder="Name">
其中“abc”类似于“collection[selectedIndex].prop”
当然,如果 selectedIndex 不可变,我可以使用 collection.1.prop
或collection[1].prop
...但是我已经尝试了所有可能的组合并查找了文档,但我不知道如何做到这一点...当然有可能吗?
最佳答案
你几乎做到了:
<input type="text" name="title" value="{{collection[selectedIndex].prop}}" placeholder="Name">
看来您需要防范不存在的值(或设置默认值),请参阅 http://jsfiddle.net/m199umtv/
关于ractivejs - 活跃 : How to access a variable integer index keypath of an array in a Ractive view,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27512766/