-
Notifications
You must be signed in to change notification settings - Fork 1.8k
wxParse多数据循环使用方法
Di edited this page Dec 6, 2016
·
2 revisions
介绍如何使用wxParse在回复等多条HTML共同渲染的方法
/**
* WxParse.wxParseTemArray(temArrayName,bindNameReg,total,that)
* 1.temArrayName: 为你调用时的数组名称
* 3.bindNameReg为循环的共同体 如绑定为reply1,reply2...则bindNameReg = 'reply'
* 3.total为reply的个数
*/
var that = this;
WxParse.wxParseTemArray("replyTemArray",'reply', replyArr.length, that)
- 循环绑定数据
var replyHtml0 = `<div style="margin-top:10px;height:50px;">
<p class="reply">
wxParse回复0:不错,喜欢[03][04]
</p>
</div>`;
var replyHtml1 = `<div style="margin-top:10px;height:50px;">
<p class="reply">
wxParse回复1:不错,喜欢[03][04]
</p>
</div>`;
var replyHtml2 = `<div style="margin-top:10px;height:50px;">
<p class="reply">
wxParse回复2:不错,喜欢[05][07]
</p>
</div>`;
var replyHtml3 = `<div style="margin-top:10px;height:50px;">
<p class="reply">
wxParse回复3:不错,喜欢[06][08]
</p>
</div>`;
var replyHtml4 = `<div style="margin-top:10px; height:50px;">
<p class="reply">
wxParse回复4:不错,喜欢[09][08]
</p>
</div>`;
var replyHtml5 = `<div style="margin-top:10px;height:50px;">
<p class="reply">
wxParse回复5:不错,喜欢[07][08]
</p>
</div>`;
var replyArr = [];
replyArr.push(replyHtml0);
replyArr.push(replyHtml1);
replyArr.push(replyHtml2);
replyArr.push(replyHtml3);
replyArr.push(replyHtml4);
replyArr.push(replyHtml5);
for (let i = 0; i < replyArr.length; i++) {
WxParse.wxParse('reply' + i, 'html', replyArr[i], that);
if (i === replyArr.length - 1) {
WxParse.wxParseTemArray("replyTemArray",'reply', replyArr.length, that)
}
}
- 模版使用
<block wx:for="{{replyTemArray}}" wx:key="">
回复{{index}}:<template is="wxParse" data="{{wxParseData:item}}"/>
</block>