今天打算把一个表格做成自定义组件,结果发现了一个大坑!!貌似官方文档上并没有对这里进行说明,所以希望能帮到遇到同样问题的同学。本人小白,技术能力不是很强,望说错的地方大神多多指点~
下面进入正题
-------------------------------------<华丽的分割线>----------------------------------------------
首先明确,我们在wxml中作条件判断的时候常用的是
<block wx:if="{{goodDetail[attributeBoList].length > 0}}"> <view class="table"> <view class="tr"> <block wx:key="testList-th" wx:for="{{goodDetail[attributeBoList]}}"> <view class="th">{{item[attributeModel][displayName]}} |
那这时候我想把class="table"的那一段打成组件。所以,坑开始了。
按照正常的流程,各种数据传递,引用之类的全部操作完毕,组件wxml为:
<view class="table"> <view class="tr"> <block wx:key="testList-th" wx:for="{{goodDetail[attributeBoList]}}"> <view class="th"> {{item[attributeModel][displayName]}} |
页面wxml为:
<nstable goodDetail="{{goodDetail}}" attributeBoList="attributeBoList" attributeModel="attributeModel" displayName="displayName" attributeValueModelList="attributeValueModelList" attributeVal="attributeVal" tableTip="{{tableTip}}"> |
结果我每次加载表格,都会报错: Expect END descriptor with depth 0 but get another
经过一次次排查,发现竟然是不能直接在block标签内引用自定义组件!
所以当我把block标签一起打入组件之后:
<block wx:if="{{goodDetail[attributeBoList].length > 0}}"> <view class="table"> <view class="tr"> <block wx:key="testList-th" wx:for="{{goodDetail[attributeBoList]}}"> <view class="th"> {{item[attributeModel][displayName]}} |
ok~~~~一切正常!所以这个坑给大家提个醒,希望能帮助大家解决这种问题,好了老板要过来查岗了,溜了溜了...

并且我尝试过自定义组件没有任何数据的情况下,在block中引用也是报正文描述的错,希望是我写的有问题,官方减少点压力2333333
@LastLeaf
this.data.test = '123';
this.setData(this.data);
这种方式算是直接赋值吗....