前端如何通过接口数据实现文件文件夹的系统?

后端传的json数据
{
code:200,
list:[
  {
     type:1,
     path:'www.file.xxxxx',
     name:'xx',
     suffix: ,
     parentid:123
     ...
  },
 {
     type:2,
     path:'www.file.xxxxx',
     name:'zzz',
     suffix: ".xlsx",
     parentid: null
     ...
  }
  ...
]
}
type 1为文件夹 2为文件(文件可能是pdf,png,wrod)
<scroll-view class='fmm-contont' scroll-y='true'>
       <block wx:for="{{files}}" wx:for-item="file" wx:key="*this" >
            <view class='file-item' data-id='{{file.id}}' catchtap='onFileTap' wx:if="{{file.type != 1}}">
              <text>{{file.fileName}}</text>
            </view>
            <view wx:else>
            <view class='floder-item' data-id='{{file.parentid}}' catchtap='onFloderTap'>
              <text>{{file.fileName}}</text>
            </view>
            ...
            </view>
       </block>
    </scroll-view>

这个接口返回第一层级的文件和文件夹可以遍历出来,点击文件夹给这个接口传一个parentid可以获取到第二个层级的数据,但是wxml我该如何去遍历呢?给.floder-item下边再写一个wx:for="{{childfiles}}"吗?如果底下还有第三第四级怎么办?没有一点思路

阅读 2.6k
1 个回答

递归遍历获取

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题