收藏
回答

request请求的数据用wx:for循环渲染

success: function (res) {

that.setData({

listData: res.data.StaffDetail

})

}

<block wx:for="{{listData}}" wx:for-item="item">

<view class="tr">

<view class="td-2">{{item.SubjectPname}}</view>

<view class="td-2">{{item.Price}}</view>

<view class="td-2">{{item.SubTotal}}</view>

<view class="td-2">{{item.Number}}</view>

</view>

</block>

渲染失败,

res.data.StaffDetail数据是

{"SubjectPname":"技术负责人","SubjectName":null,"Price":"0.4~0.6","SubTotal":"0.4~0.6","Number":1},

{"SubjectPname":"中级职称","SubjectName":"结构;材料或化工;(必齐全)","Price":"0.67~0.7","SubTotal":"2~2.1","Number":3}



如果这样的话就能渲染成功:

success: function (res) {

that.setData({

listData:

{"SubjectPname":"技术负责人","SubjectName":null,"Price":"0.4~0.6","SubTotal":"0.4~0.6","Number":1},

{"SubjectPname":"中级职称","SubjectName":"结构;材料或化工;(必齐全)","Price":"0.67~0.7","SubTotal":"2~2.1","Number":3}

})

}

<block wx:for="{{listData}}" wx:for-item="item">

<view class="tr">

<view class="td-2">{{item.SubjectPname}}</view>

<view class="td-2">{{item.Price}}</view>

<view class="td-2">{{item.SubTotal}}</view>

<view class="td-2">{{item.Number}}</view>

</view>

</block>



回答关注问题邀请回答
收藏

20 个回答

  • 平风
    平风
    2017-11-03

    console.log(res); 加在that.setData前面,然后控制台展开相关节点截图

    2017-11-03
    有用
    回复
  • 2017-11-03

    我大体知道啥原因了,我输出的数据是string,listdata后面要输出数组格式,问个问题,我怎么把

    这串string转成数组

    2017-11-03
    有用
    回复
  • 平风
    平风
    2017-11-03

    你把res打印出来看下

    2017-11-03
    有用
    回复
  • 2017-11-03


    这样的

    2017-11-03
    有用
    回复
  • 2017-11-03

    外面是有【】这个的,接口返回的时候去掉了,有没有他都不行,数据直接写上就可以渲染

    2017-11-03
    有用
    回复
  • 平风
    平风
    2017-11-03

    把console.log打印的内容截图发来看下

    2017-11-03
    有用
    回复
  • 2017-11-03

    是一致的,输入的数据是这种格式

    {"SubjectPname":"技术负责人","SubjectName":null,"Price":"0.4~0.6","SubTotal":"0.4~0.6","Number":1},

    {"SubjectPname":"中级职称","SubjectName":"结构;材料或化工;(必齐全)","Price":"0.67~0.7","SubTotal":"2~2.1","Number":3}

    把这个数据直接写在listData:后面就可以直接渲染成功

    2017-11-03
    有用
    回复
  • 平风
    平风
    2017-11-03

    请在that.setData之前通过console.log(res, res.data.StaffDetail)打印出相关内容,看数据是否与期望的一致。

    2017-11-03
    有用
    回复
  • 2017-11-03

    json格式

    {"SubjectPname":"技术负责人","SubjectName":null,"Price":"0.4~0.6","SubTotal":"0.4~0.6","Number":1},

    {"SubjectPname":"中级职称","SubjectName":"结构;材料或化工;(必齐全)","Price":"0.67~0.7","SubTotal":"2~2.1","Number":3}


    2017-11-03
    有用
    回复
  • 叶后减
    叶后减
    2017-11-02

    request回调的数据什么格式

    2017-11-02
    有用
    回复

正在加载...

登录 后发表内容