<block wx:for="{{row}}" wx:for-item="item" wx:for-index="x" wx:key="key2">
<view class="absolute canGoHere"
style="width:{{latticeWidth}}px;height:{{latticeWidth}}px;left:{{latticeWidth * (x - 1)}}px;top:{{latticeWidth * (y-1)}}px;background-color:{{bgColorOfCanGoHere}};"
></view>
</block>
关于动态wxss的代码不要太长, 在IDE中横向滚动就少一些,我想到一些方法:
1、如果style标签支持折行,在编译时不报语法错误,则挺好的:
<block wx:for="{{row}}" wx:for-item="item" wx:for-index="x" wx:key="key2">
<view class="absolute canGoHere"
style="width:{{latticeWidth}}px;height:{{latticeWidth}}px;left:{{latticeWidth * (x - 1)}}px;
top:{{latticeWidth * (y-1)}}px;background-color:{{bgColorOfCanGoHere}};"
></view>
</block>
2、如果支持<wxss></wxss>标签,则是极好的, 代码不但可以变短,而且更直观,还沿用了wxss的编码习惯,请看“魔法”(推荐):
<wxss>
.high-light{
width:{{latticeWidth}}px;
height:{{latticeWidth}}px;
background-color:{{bgColorOfCanGoHere}};
}
</wxss>
<block wx:for="{{row}}" wx:for-item="item" wx:for-index="x" wx:key="key2">
<view class="absolute canGoHere high-light"
style="left:{{latticeWidth * (x - 1)}}px;top:{{latticeWidth * (y-1)}}px;"
></view>
</block>
3、为了代码可以变短,还有一种“魔法”:(不直观)
<block wx:for="{{row}}" wx:for-item="item" wx:for-index="x" wx:key="key2">
<view class="absolute canGoHere high-light"
style="{{calculateItsStyle(x,y);}}"
></view>
</block>
4、可能是最土的方法(也不直观)
<block wx:for="{{row}}" wx:for-item="item" wx:for-index="x" wx:key="key2">
<view class="absolute canGoHere high-light"
style="{{calculatedStyle}};left:{{latticeWidth * (x - 1)}}px;top:{{latticeWidth * (y-1)}}px;"
></view>
</block>
不知阁下怎么看?