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>
console.log(res); 加在that.setData前面,然后控制台展开相关节点截图
我大体知道啥原因了,我输出的数据是string,listdata后面要输出数组格式,问个问题,我怎么把
这串string转成数组
你把res打印出来看下
这样的
外面是有【】这个的,接口返回的时候去掉了,有没有他都不行,数据直接写上就可以渲染
把console.log打印的内容截图发来看下
是一致的,输入的数据是这种格式
【
{"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:后面就可以直接渲染成功
请在that.setData之前通过console.log(res, res.data.StaffDetail)打印出相关内容,看数据是否与期望的一致。
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}
】
request回调的数据什么格式