赞
踩
class ExpCellDetailP0J0 { int num;//序号 SizeDetail sizeDetail; //格口尺寸参数 bool isSelected; //是否选中 SelectFileData backFillFile;//本地格口规格设置弹窗里填写后的回填中显示用的格口图片、视频文件 ExpCellDetailP0J0( {this.num, this.sizeDetail, this.isSelected = false, // this.backFillFile, }) { this.sizeDetail = sizeDetail ?? SizeDetail(); } ExpCellDetailP0J0.fromJson(dynamic json) { num = json['num']; sizeDetail = json['sizeDetail'] != null ? SizeDetail.fromJson(json['sizeDetail']) : null; } Map<String, dynamic> toJson() { final map = <String, dynamic>{}; map['num'] = num; if (sizeDetail != null) { map['sizeDetail'] = sizeDetail.toJson(); } return map; } } class SizeDetail { int longSize; //长 int wideSize; //宽 int deepSize; //深 SizeDetail({this.longSize, this.wideSize,this.deepSize}); SizeDetail.fromJson(dynamic json) { longSize = json['longSize']; wideSize = json['wideSize']; deepSize = json['deepSize']; } Map<String, dynamic> toJson() { final map = <String, dynamic>{}; map['longSize'] = longSize; map['wideSize'] = wideSize; map['deepSize'] = deepSize; return map; } }
List<List<ExpCellDetailP0J0>> _expCellSpecsList = []; //批量设置 _batchSet(ExpCellDetailP0J0 cellInfo){ print('批量赋值'); for (var row in _expCellSpecsList) { for (var cell in row) { cell.publishStatus = cellInfo.publishStatus; cell.row = cellInfo.row; cell.column = cellInfo.column; cell.buyChargeDetailList = cellInfo.buyChargeDetailList; cell.rateChargeDetailList = cellInfo.rateChargeDetailList; cell.userCellFileUrlPOJODetail = cellInfo.userCellFileUrlPOJODetail; cell.sizeDetail = cellInfo.sizeDetail; cell.isSelected = false; cell.backFillFile = cellInfo.backFillFile; } } setState(() {}); } _singleSet(){ for (var row in _expCellSpecsList) { for (var cell in row) { print('cell =${cell.toJson()}'); } } print(' row= $row column= $column'); ExpCellDetailP0J0 resultBean = result; print('填写前的回填:${_expCellSpecsList[row][column].toJson()}'); // _expCellSpecsList[row][column].sizeDetail = resultBean.sizeDetail; _expCellSpecsList[row][column].sizeDetail.deepSize = resultBean.sizeDetail.deepSize; _expCellSpecsList[row][column].sizeDetail.longSize = resultBean.sizeDetail.longSize; print('填写后的回填:${_expCellSpecsList[row][column].toJson()}'); for (var row in _expCellSpecsList) { for (var cell in row) { print('cell2 =${cell.toJson()}'); } } _setBackFillFile(row,column); setState(() {}); }
问题描述:给二维数组批量赋值后,再进行单个对象的深度赋值后_expCellSpecsList[row][column].sizeDetail.deepSize = resultBean.sizeDetail.deepSize;
查询二维数组 print('cell2 =${cell.toJson()}');
打印出来却是整个数组的deepSize参数都被赋值了;
更改:将赋值方法从_expCellSpecsList[row][column].sizeDetail.longSize = resultBean.sizeDetail.longSize;
改为_expCellSpecsList[row][column].sizeDetail = resultBean.sizeDetail;
后正常了。
问题原因在哪里?求路过的大神指点一下
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。