rich-text富文本使用问题
发布于 5 年前 作者 shiwei 3975 次浏览 来自 问答

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

<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
             }]
           }]
        });

还有,能否给个实例让我学习下,谢谢!我的邮箱是:[email protected]

2 回复

谢谢,向你学习

用法不对,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
    }]
  }]
});
回到顶部