要实时改变数组里的数值:
<view class='sign' bindtap='addNum' data-index="{{index}}">+</view>
传的值是index,要使用this.setData({name:value})
动态的index,要另外赋值:let proInf = 'proInf[' + index + '].num'; proInf在this.setData里要加中括号:[ proInf ]
addNum: function(e) {
let index = e.currentTarget.dataset.index;
let proInf = 'proInf[' + index + '].num';
this.setData({
[proInf]: ++this.data.proInf[index].num
})
},
动态改变样式:
改变颜色:style="color: {{index== 0 ?'#eb6100':' '}}"
改变类:class="attBtn {{_num== index ?'getAttr':' '}}"
获取input里的内容。
<input type='text' bindinput="getInputValue" />
用bindinput=“方法”获取input里的值
getInputValue(e) {
this.modalInputValue = e.detail.value;
},
页面之间传值:
goEvaluationList() {
var goods_id = this.data.goods_id;
wx.navigateTo({
url: '/pages/evaluationList/evaluationList?goods_id=' + goods_id
})
},
onLoad: function ({ goods_id }) {
this.setData({
goods_id: goods_id
})
},
onShow: function (options){
this.getEvaluationList(this.options.goods_id)
}
Onload的options是其他页面传过来的值,不需要加this;
Onshow的参数是options;调用的是传到onload的值;
goOrderList: function (e) {
var orderstate = e.currentTarget.dataset.orderstate;
wx.navigateTo({
url: '/pages/orderList/orderList?state=' + orderstate,
})
},
onLoad(options){
this.setData({
order_status: options.state
})
},
onShow(options) {
this.getOrderList({
order_status: this.options.state,
});
},
字符串转json: var specJson = JSON.parse(res.data.refund_goods[0].spec_json);
自我循环调用函数
var interval;
interval = setInterval(function() {
wx.getBluetoothDevices({
success: function(res) {
console.log(res.devices)
that.setData({
bluetoothCount: res.devices.length
})
},
})
//循环执行的语句,
//直到符合条件,结束循环;
if (that.data.btnEndTitle === '下一步,信息确认') {
clearInterval(interval)
}
}, 1000)