<block wx:for="{{a}}" wx:for-item="item" >
<view data-index="{{index}}">
<block wx:for="{{item.b}}" >
<input type="text" bindfocus="index" data-index="{{index}}">
</block>
<view>
</block>
input获得焦点的时候怎么获取上一层循环的index呢?
网友回复:
将 父元素的下标值存下来
可以使用wx:for-index属性,例如
<view wx:for="{{array}}" wx:for-index="idx" wx:for-item="itemName">
文档见:https://mp.weixin.qq.com/debug/wxadoc/dev/framework/view/wxml/list.html
学习了
<block wx:for="{{a}}" wx:for-index="father_index" wx:for-item="father_item">
<view data-index="{{father_index}}">
<block wx:for="{{father_item}}" wx:for-index="son_index" wx:for-item="son_item">
<input type="text" value="{{son_item.value+father_index+son_index}}" data-index="{{father_index}}" />
</block>
</view>
</block>
data: {
a: [
[{ value: "a" }, { value: "b" }, { value: "c" }],
[{ value: "d" }, { value: "e" }, { value: "f" }],
[{ value: "g" }, { value: "h" }, { value: "i" }]
]
}
咫尺开发论坛——小乐