原代码:
function change_start_price(e) {
dispatch({
type : 'groupManageModel/updateState',
payload : {
start_price : e
}
});
}
function change_end_price(e) {
dispatch({
type : 'groupManageModel/updateState',
payload : {
end : e
}
});
}
修改之后的代码:
function change_val(key, e) {
dispatch({
type : 'groupManageModel/updateState',
payload : {
[key] : e
}
});
}
调用时这样调用:
change_val.bind(this, 'start_price')
change_val.bind(this, 'end_price')
原代码:
if(addModalTitle == '编辑'){
// 编辑商品组
dispatch({
type: 'groupManageModel/goodsRuleupdate',
payload: {
id,
gePrice : select_price ? start_price : undefined,
ltPrice : select_price ? end_price : undefined,
},
});
}
else{
// 创建商品组
dispatch({
type: 'groupManageModel/goodsRulecreate',
payload: {
gePrice : select_price ? start_price : undefined,
ltPrice : select_price ? end_price : undefined,
},
});
}
修改之后的代码:
let commonPayload = {
gePrice : select_price ? start_price : undefined,
ltPrice : select_price ? end_price : undefined,
};
if(addModalTitle != '编辑'){
// 创建商品组
dispatch({
type: 'groupManageModel/goodsRulecreate',
payload: commonPayload,
});
}
else{
// 编辑商品组
dispatch({
type: 'groupManageModel/goodsRuleupdate',
payload: {
id,
...commonPayload
},
});
}
原代码:
var arr = [1, 2];
for(var i = 0;i < arr.length;i++){
console.log(arr[i]);
}
修改之后的代码:
var arr = [1, 2];
for(var i = 0,len = arr.length;i < len;i++){
console.log(arr[i]);
}