WX:FOR的使用问题?

小程序 文章 2020-08-10 17:21 616 0 全屏看文

AI助手支持GPT4.0

WX:FOR的使用问题?WX: How to use FOR?

WX:FOR的使用问题?

本人使用WX:FOR 循环渲染了第二层标签,右下角有个圆形ICON标签,默认初始化是不显示的。第二层的每个标签都会跟着一些问题。本人的设计是第三层问题只要被回答了,ICON标签就显示。这样意味着,第二层标签在渲染的时候要赋予每个ICON标签一个ID值,并唯一标识其是否显示,比如用wx:if来搞定。可本人在如何充分利用WX:FOR时生成这些需具备能控制其是否显示的唯一标识的时候没想到有什么有效的办法?请高人指定!谢谢。注意是;第三层问题回答了,就显示对应的第二册标签。当然第二层标签点击了,显示自己相关的问题。如下下图中,6个标签对应6组问题。麻烦了。

下面写的这个wx:if="out{{index+1}}" 貌似是字符串,无法起作用?

WXML:

<view class="layer2boxwx:if="{{isShowOut}}">

  <view wx:for="{{outlist}}class="item-list {{index+1==current?'select':''}}wx:key="idbindtap="onClickL2Outdata-id="{{item.id}}">

    <view>{{index+1}}_{{item.title}} view>

    <icon wx:if="out{{index+1}}type="successsize="20rpxcolor="{{iconcolor}}"> icon>

   view>

view>



I used Wx: for loop to render the second layer label. There is a circular icon label in the lower right corner. The default initialization is not displayed. Each label in the second layer has some problems. My design is the third level of questions, as long as they are answered, the icon tag will be displayed. This means that each icon tag should be given an ID value when rendering, and uniquely identify whether it is displayed, such as Wx: if. But when I make full use of Wx: for, I didn't think of any effective way to generate the unique identification that can control whether it is displayed or not? Please specify! thank you. Note: the third question is answered, and the corresponding volume 2 label will be displayed. Of course, the second layer of tabs Click to display their own related questions. In the following figure, six tags correspond to six groups of questions. Sorry for the inconvenience. The Wx: if = out {index + 1}} "seems to be a string, so it doesn't work? WXML: {{index+1}}_ * item.title }}view> icon> view> view>

回答:

?:

wx:if 成立的条件是 不为空 不为null 不为undefined 不为负数。但是你这样子写 他都是true。

Jason_亮 🇨🇳:明白。那怎么写呢?或者使用别的思路?刚才根据别人的建议,写成"{{out[index+1]}}"也不行。
?:你这里第三层和第二层是怎么对应的?还是说第三层就在第二层的下面?也是第二层循环里的子元素?
Jason_亮 🇨🇳:第二层每个大控件对应第三层一组问题,问题回答即显示其第二层对应标签右下角的小ICON标签。第三层就在第二层的下面,第三层根据第二层控件的点击出来,究竟循环出来还是罗列出来,不在当前问题范围。
Distance:

wx:if="out{{index+1}}" 因为out是字符串所以不管你index+1是什么,他都是true

Jason_亮 🇨🇳:明白。那怎么写呢?或者使用别的思路?刚才根据别人的建议,写成"{{out[index+1]}}"也不行。
Why not?:

wx:if="out{{index+1}}" 不知道out是啥东西,但应该是个变量吧,你得这么写:wx:if="{{out[index+1]}}"

Jason_亮 🇨🇳:这样写也不可以啊,index+1外面不论是()或[]均不可以,这样,连wxml渲染都看不到了。我这里探讨的不仅仅是这个写法的问题,估计这么写根本就写不出准确的方式,需要换个别的思路?有建议吗?

-EOF-

AI助手支持GPT4.0