遍历字段名称(键)
<view wx:for="{{classType}}" wx:for-index="key">{{key}}</view>
场景:遍历C1、C2
{{[circle.tagList[item.project_tag]]}}
\n换行数据
1、新建filter.wxs,放入lib-css文件夹下面,我是这么放的,大家根据自己的情况定。
//filter.wxs
var format = function (text) {
if (!text) {
return
}
var reg = getRegExp('\\\\n', 'g')
return text.replace(reg,'\n')
}
module.exports = {
format:format
}
2、在页面导入刚刚新建的wxs模块
<!--只能使用相对路径(绝对路径只需要/lib后面的路径),并需要定义module-->
<wxs src="../../lib/css/filter.wxs" module="util"></wxs>
3、在页面中需要转化的地方转一下
<!--要用text标签,因为text才支持\n-->
<text class="gray">{{util.format(item.description)}}</text>
场景:后台接口返回带\n的动态文案
html img数据
1、html处理
<rich-text nodes="{{introduce}}"></rich-text>
2、样式处理
const regex = new RegExp('<img', 'gi')
const temp_article_content = interfaceData.replace(regex, `< img style="max-width: 100%;"`);
that.setData({
introduce:temp_article_content,
})
场景:用户使用富文本编辑器添加的文案中存在img就需要对他的宽度做限制,因为在这里要使用所以在页面就没法设置样式了,只能通过js将返回的数据转化一下