收藏
回答

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

    基本功没过关,eval或JSON.parse可以实现字符串转对象,不明白自行百度。

    2017-11-03
    有用
    回复
  • 君志未酬
    君志未酬
    2017-11-03


    console.log(arr),数组没拼对,怎么拼成我想要的呢种的呢


    2017-11-03
    有用
    回复
  • 君志未酬
    君志未酬
    2017-11-03

    success: function (res) {

    var arr = [];

    arr.push(res.data.StaffDetail.split('},');

    console.log(arr[0]);

    that.setData({

    listData: arr[0]

    })

    },

    console.log(arr[0]);输出undefined,数组出错了?


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

    看你的截图怎么是二维数组,你再试着打印下console.log(res.data.StaffDetai[0]);

    2017-11-03
    有用
    回复
  • 君志未酬
    君志未酬
    2017-11-03


    这个是转成的数组

    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},

    {"SubjectPname":"八大员","SubjectName":"质量员;施工员;安全员;造价员;","Price":"0.3","SubTotal":"3","Number":10},

    {"SubjectPname":"技工","SubjectName":"中级技工证;","Price":"0.1","SubTotal":"1.5","Number":15}


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

    你确定res.data.StaffDetail没写错?console.log(res.data.StaffDetail)看看输出的什么

    2017-11-03
    有用
    回复
  • 君志未酬
    君志未酬
    2017-11-03

    我把他改成了数组也不行

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

    这不问题就出来了,你的StaffDetail是个对象,不是数组

    2017-11-03
    有用
    回复
  • 君志未酬
    君志未酬
    2017-11-03


    staffdetail的数据格式和MajorLevel的格式是一样的

    2017-11-03
    有用
    回复

正在加载...

登录 后发表内容