根据条件动态生成wxml元素的问题
前端代码
< block wx:for = '{{sudoku}}' wx:key = '*this' > < block wx:if = '{{index%9==0}}' > < view class = 'tr' > </ block > <!--other codes here--> < block wx:if = '{{index%9==0}}' > </ view > </ block > </ block > |
js代码:
data: { sudoku: new Array(81) }, |
但这样报错,该如何实现类似功能?效果希望是这样的
5 回复
我最后放弃了,改成如下代码方式了:
< view class = 'table' > < block wx:for = '{{sudoku}}' wx:key = '*this' > < block wx:if = '{{index%9==0}}' > < view class = 'tr line{{index/9 + 1}}' > < view class = 'td col1 {{(index/9==0||index/9==1 || index/9==2 || index/9==6 ||index/9==7 || index/9==8)?"":"tdbg"}} {{cellSelected==index?"cell-selected":"cell"}}' data-cell = '{{index}}' bindtap = 'onCellClick' >0</ view > < view class = 'td col2 {{(index/9==0||index/9==1 || index/9==2 || index/9==6 ||index/9==7 || index/9==8)?"":"tdbg"}} {{cellSelected==index+1?"cell-selected":"cell"}}' data-cell = '{{index+1}}' bindtap = 'onCellClick' >0</ view > < view class = 'td col3 {{(index/9==0||index/9==1 || index/9==2 || index/9==6 ||index/9==7 || index/9==8)?"":"tdbg"}} {{cellSelected==index+2?"cell-selected":"cell"}}' data-cell = '{{index+2}}' bindtap = 'onCellClick' >0</ view > < view class = 'td col4 {{(index/9==3||index/9==4 || index/9==5)?"":"tdbg"}} {{cellSelected==index+3?"cell-selected":"cell"}}' data-cell = '{{index+3}}' bindtap = 'onCellClick' >0</ view > < view class = 'td col5 {{(index/9==3||index/9==4 || index/9==5)?"":"tdbg"}} {{cellSelected==index+4?"cell-selected":"cell"}}' data-cell = '{{index+4}}' bindtap = 'onCellClick' >0</ view > < view class = 'td col6 {{(index/9==3||index/9==4 || index/9==5)?"":"tdbg"}} {{cellSelected==index+5?"cell-selected":"cell"}}' data-cell = '{{index+5}}' bindtap = 'onCellClick' >0</ view > < view class = 'td col7 {{(index/9==0||index/9==1 || index/9==2 || index/9==6 ||index/9==7 || index/9==8)?"":"tdbg"}} {{cellSelected==index+6?"cell-selected":"cell"}}' data-cell = '{{index+6}}' bindtap = 'onCellClick' >0</ view > < view class = 'td col8 {{(index/9==0||index/9==1 || index/9==2 || index/9==6 ||index/9==7 || index/9==8)?"":"tdbg"}} {{cellSelected==index+7?"cell-selected":"cell"}}' data-cell = '{{index+7}}' bindtap = 'onCellClick' >0</ view > < view class = 'td col9 {{(index/9==0||index/9==1 || index/9==2 || index/9==6 ||index/9==7 || index/9==8)?"":"tdbg"}} {{cellSelected==index+8?"cell-selected":"cell"}}' data-cell = '{{index+8}}' bindtap = 'onCellClick' >0</ view > </ view > </ block > </ block > </ view > |