怎么用wx:for只循环出type为a的数据
如何循环出数组中之地当的某一条数据?How to loop out a certain piece of data in the array?
如何循环出数组中之地当的某一条数据?怎么用wx:for只循环出type为a的数据
How to use Wx: for to only loop out data of type A
回答:
<view wx:for="{{audios}}" wx:key="{{item.idex}}"> <view wx:if="{{item.type == 'a'}}"> <view>{{item.name}}view> view>view>
先filter一下或者在wx:for循环里面做判断
const res = audios.filter(function(value, index, array) { if ('a' === value.type) { return true }})
<view wx:for="audios" wx:key="idex"> <view wx:if="{{item.type == 'a'}}">view>view>
audios[0]
<block wx:if="{{item.type=='a'}}">block>
原文出处:如何循环出数组中之地当的某一条数据?
<block wx:for="{{audios}}" wx:key="name"> <view wx:if="{{item.type == 'a'}}">{{item.a}}<view>block>