rich-text富文本使用问题

发布于 6 年前作者 shiwei4155 次浏览最后编辑 6 年前来自 ask

你好,这个是如何动态取后台数据赋值到前台显示的,谢谢!

<view class=“btnList”>
 <rich-text type = “node” nodes=“{{nodes}}” bindtap=“tap”  />
</view>

    nodes: [{
      name: ‘div’,
      attrs: {
        class: ‘div_class’,
        style: ‘line-height: 150px; color:blue;’
      },
      children: [{
        type: ‘text’,
        text: ‘这是要加后台数据的,如何加上’
      }]
    }],

后台数据是:var showTxt = allInfo + routes[0][0];

我用这种方法根本不管用,没用变化,谢谢!

       that.setData({
           nodes: [{
             children:[{
             type: ‘text’,
             text: showTxt
             }]
           }]
        });

还有,能否给个实例让我学习下,谢谢!我的邮箱是:admins@163.com

2 回复
tao94
tao941 楼6 年前

谢谢,向你学习

zhengyan
zhengyan2 楼4 年前

用法不对,setData里的nodes值没有name,所以不会渲染任何结点,你应该把完整的nodes值set进去,如下:

var showTxt = allInfo + routes[0][0];
that.setData({
  nodes: [{
    name: 'div',
    attrs: {
      class: 'div_class',
      style: 'line-height: 150px; color:blue;'
    },
    children: [{
      type: 'text',
      text: showTxt
    }]
  }]
});