前端样式
解析:每点一下新增,页面就新增一个【删除行】,传递给后端的数据解析为一个数组
需求:
需要把上图红框中的动态数据拼成一个数组
"iccidList":[{
"start": 123,
"end": 567
},{
"start": 890,
"end": 1111
}]
后端代码
if ($this->request->isPost()) {
$data = $this->request->getInput();
$json_data = json_decode($data, true);
$json_data = array_diff($json_data,['']);
$iccidList = [];
foreach ($json_data as $key=>&$v) {
if(substr($key,0,3) == 'sta'){
$iccidList[] = array(
'startIccid' => $v
);
}
if(substr($key,0,3) == 'end'){
$arr = $iccidList[count($iccidList) - 1];
$arr['endIccid'] = $v;
$iccidList[count($iccidList) - 1] = $arr;
}
}
$json_data['iccidList'] = $iccidList;
$saleReturn = Paas::request('/sim/abnormal/return/insertIntoAbnormalReturnGoods', $json_data);
if ($saleReturn['status'] == 0){
return $this->success('新增退货成功');
}elseif($saleReturn['status'] == 5017){
return $this->error("输入内容错误,请重新输入");
}else{
return $this->error('新增退货失败,请重新输入');
}
} else {
return $this->fetch();
}
打印拼接结果:
|