引用template代码
<view wx:for="{{items.children}}" wx:key="id" wx:for-index="cindexs" wx:for-item="items">
<template is="CommentItem" data="{{item,items,cindexs,cindexs}}"></template>
</view>
template代码如下
<template name="CommentItem">
<--省略部分-->
<block wx:if="{{items.children}}">
<view wx:for="{{items.children}}" wx:key="id" wx:for-index="cindexs" wx:for-item="items">
<template is="CommentItem" data="{{item,items,cindexs,cindexs}}"></template>
</view>
</block>
</template>
其中嵌套部分无法正常显示数据,不知道是哪里出现了问题?
===========================================================
目前解决方法是写多个<template>,修改名字:
<template name="CommentItem">
<--省略部分-->
<block wx:if="{{items.children}}">
<view wx:for="{{items.children}}" wx:key="id" wx:for-index="cindexs" wx:for-item="items">
<template is="CommentItem1" data="{{item,items,cindexs,cindexs}}"></template>
</view>
</block>
</template>
<template name="CommentItem1">
<--省略部分-->
<block wx:if="{{items.children}}">
<view wx:for="{{items.children}}" wx:key="id" wx:for-index="cindexs" wx:for-item="items">
<template is="CommentItem2" data="{{item,items,cindexs,cindexs}}"></template>
</view>
</block>
</template>
<template name="CommentItem2">
<--省略部分-->
<block wx:if="{{items.children}}">
<view wx:for="{{items.children}}" wx:key="id" wx:for-index="cindexs" wx:for-item="items">
<template is="CommentItem3" data="{{item,items,cindexs,cindexs}}"></template>
</view>
</block>
</template>
<--以此类推-->
源码如下:
<template name="CommentItem">
<view class="comment-header">
<view class="comment-header-left" catchtap="userTap" data-uid="{{items.user}}">
<image class="comment-avatar" src="{{items.user_avatar}}">
</image>
<view class="comment-user-date">
<text>{{items.user_nickname}}</text>
<text>{{items.create_time}}</text>
</view>
</view>
<view class="comment-header-right">
<view>{{filters.toFix(items.like_count)}}</view>
<image data-id="{{items.id}}" data-cmtindex="{{cindex}}" data-cmtindexs="{{cindexs}}" bindtap="tapCommentslike" src="/image/heart-fill.png" wx:if="{{items.is_like}}">
</image>
<image data-id="{{items.id}}" data-cmtindex="{{cindex}}" data-cmtindexs="{{cindexs}}" bindtap="tapCommentslike" src="/image/heart-line.png" wx:else></image>
<text wx:if="{{items.user == item.current_user_id}}" data-id="{{items.id}}" data-cmtindex="{{cindex}}" data-cmtindexs="{{cindexs}}" bindtap="tapDeleteComments">删除</text>
</view>
</view>
<view class="comment-content" bindtap="tapComment" data-id="{{item.id}}" data-reply="{{items.user_nickname}}" data-userid="{{items.user}}">
<view class="commentconent">
<view class="contentinfo">
<block wx:if="{{item.user != items.user}}">
回复<text>{{item.user_nickname}}</text>:
</block>
<block wx:if="{{items.content != null}}">
{{items.content}}
</block>
</view>
</view>
<image wx:if="{{items.image != null && items.image != ''}}" class="img-list" lazy-load='{{true}}' catchtap="previewImgFunc" data-list="{{items.imgList}}" data-src="{{items.image}}" mode="aspectFill" src="{{items.image}}"></image>
</view>
<block wx:if="{{items.children}}">
<view wx:for="{{items.children}}" wx:key="id" wx:for-index="cindexs" wx:for-item="items">
<template is="CommentItem" data="{{item,items,cindexs,cindexs}}"></template>
</view>
</block>
</template>
请具体描述问题出现的流程,并提供能复现问题的简单代码片段(https://developers.weixin.qq.com/miniprogram/dev/devtools/minicode.html)。
</view>
</view>
<view class="comment-content" bindtap="tapComment" data-id="{{item.id}}" data-userid="{{item.user}}" data-reply="{{item.user_nickname}}">
<view class="commentconent">
<view class="contentinfo">
<block wx:if="{{item.content != null}}">
{{item.content}}
</block>
</view>
</view>
<image wx:if="{{item.image != null && item.image != ''}}" class="img-list" lazy-load='{{true}}' catchtap="previewImgFunc" data-list="{{item.imgList}}" data-src="{{item.image}}" mode="aspectFill" src="{{item.image}}"></image>
</view>
<view class="replay-content" wx:for="{{item.children}}" wx:key="id" wx:for-index="cindexs" wx:for-item="items">
<view class="comment-header">
<view class="comment-header-left" catchtap="userTap" data-uid="{{items.user}}">
<image class="comment-avatar" src="{{items.user_avatar}}">
</image>
<view class="comment-user-date">
<text>{{items.user_nickname}}</text>
<text>{{items.create_time}}</text>
</view>
</view>
<view class="comment-header-right">
<view>{{filters.toFix(items.like_count)}}</view>
<image data-id="{{items.id}}" data-cmtindex="{{cindex}}" data-cmtindexs="{{cindexs}}" bindtap="tapCommentslike" src="/image/heart-fill.png" wx:if="{{items.is_like}}">
</image>
<image data-id="{{items.id}}" data-cmtindex="{{cindex}}" data-cmtindexs="{{cindexs}}" bindtap="tapCommentslike" src="/image/heart-line.png" wx:else></image>
添加一个代码片段嘛,你这个写的,不好找问题在哪里