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>
基本功没过关,eval或JSON.parse可以实现字符串转对象,不明白自行百度。
console.log(arr),数组没拼对,怎么拼成我想要的呢种的呢
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,数组出错了?
看你的截图怎么是二维数组,你再试着打印下console.log(res.data.StaffDetai[0]);
这个是转成的数组
{"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}
你确定res.data.StaffDetail没写错?console.log(res.data.StaffDetail)看看输出的什么
我把他改成了数组也不行
这不问题就出来了,你的StaffDetail是个对象,不是数组
staffdetail的数据格式和MajorLevel的格式是一样的