Skip to content

Commit

Permalink
修复空值问题
Browse files Browse the repository at this point in the history
  • Loading branch information
xuliangzhan committed Dec 2, 2019
1 parent 1a5eaa8 commit 0549fa2
Show file tree
Hide file tree
Showing 5 changed files with 119 additions and 12 deletions.
49 changes: 45 additions & 4 deletions dist/index.common.js

Large diffs are not rendered by default.

47 changes: 44 additions & 3 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -279,14 +279,37 @@
optionProps = _renderOpts$optionPro2 === void 0 ? {} : _renderOpts$optionPro2,
_renderOpts$optionGro2 = renderOpts.optionGroupProps,
optionGroupProps = _renderOpts$optionGro2 === void 0 ? {} : _renderOpts$optionGro2;
var row = params.row,
var $table = params.$table,
row = params.row,
column = params.column;
var labelProp = optionProps.label || 'label';
var valueProp = optionProps.value || 'value';
var groupOptions = optionGroupProps.options || 'options';

var cellValue = _xeUtils["default"].get(row, column.property);

var colid = column.id;
var rest;
var cellData;

if (props.remote) {
var fullAllDataRowMap = $table.fullAllDataRowMap;
var cacheCell = fullAllDataRowMap.has(row);

if (cacheCell) {
rest = fullAllDataRowMap.get(row);
cellData = rest.cellData;

if (!cellData) {
cellData = fullAllDataRowMap.get(row).cellData = {};
}
}

if (rest && cellData[colid] && cellData[colid].value === cellValue) {
return cellData[colid].label;
}
}

if (!(cellValue === null || cellValue === undefined || cellValue === '')) {
return cellText(h, _xeUtils["default"].map(props.multiple ? cellValue : [cellValue], optionGroups ? function (value) {
var selectItem;
Expand All @@ -301,13 +324,31 @@
}
}

return selectItem ? selectItem[labelProp] : null;
var cellLabel = selectItem ? selectItem[labelProp] : value;

if (cellData && options && options.length) {
cellData[colid] = {
value: cellValue,
label: cellLabel
};
}

return cellLabel;
} : function (value) {
var selectItem = _xeUtils["default"].find(options, function (item) {
return item[valueProp] === value;
});

return selectItem ? selectItem[labelProp] : null;
var cellLabel = selectItem ? selectItem[labelProp] : value;

if (cellData && options && options.length) {
cellData[colid] = {
value: cellValue,
label: cellLabel
};
}

return cellLabel;
}).join(';'));
}

Expand Down
2 changes: 1 addition & 1 deletion dist/index.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

31 changes: 28 additions & 3 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -208,11 +208,28 @@ const renderMap = {
},
renderCell(h: Function, renderOpts: any, params: any) {
let { options, optionGroups, props = {}, optionProps = {}, optionGroupProps = {} } = renderOpts
let { row, column } = params
let { $table, row, column } = params
let labelProp = optionProps.label || 'label'
let valueProp = optionProps.value || 'value'
let groupOptions = optionGroupProps.options || 'options'
let cellValue = XEUtils.get(row, column.property)
let colid: string = column.id
let rest: any
let cellData: any
if (props.remote) {
let fullAllDataRowMap: Map<any, any> = $table.fullAllDataRowMap
let cacheCell: any = fullAllDataRowMap.has(row)
if (cacheCell) {
rest = fullAllDataRowMap.get(row)
cellData = rest.cellData
if (!cellData) {
cellData = fullAllDataRowMap.get(row).cellData = {}
}
}
if (rest && cellData[colid] && cellData[colid].value === cellValue) {
return cellData[colid].label
}
}
if (!(cellValue === null || cellValue === undefined || cellValue === '')) {
return cellText(h, XEUtils.map(props.multiple ? cellValue : [cellValue], optionGroups ? (value: any) => {
let selectItem
Expand All @@ -222,10 +239,18 @@ const renderMap = {
break
}
}
return selectItem ? selectItem[labelProp] : null
let cellLabel: any = selectItem ? selectItem[labelProp] : value
if (cellData && options && options.length) {
cellData[colid] = { value: cellValue, label: cellLabel }
}
return cellLabel
} : (value: any) => {
let selectItem = XEUtils.find(options, (item: any) => item[valueProp] === value)
return selectItem ? selectItem[labelProp] : null
let cellLabel: any = selectItem ? selectItem[labelProp] : value
if (cellData && options && options.length) {
cellData[colid] = { value: cellValue, label: cellLabel }
}
return cellLabel
}).join(';'))
}
return cellText(h, '')
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "vxe-table-plugin-iview",
"version": "1.5.7",
"version": "1.5.8",
"description": "基于 vxe-table 表格的适配插件,用于兼容 iview 组件库",
"scripts": {
"lib": "gulp build"
Expand Down

0 comments on commit 0549fa2

Please sign in to comment.