Skip to content

Commit

Permalink
merge
Browse files Browse the repository at this point in the history
  • Loading branch information
José Espinoza committed Oct 1, 2018
1 parent 80f325e commit 7296128
Showing 1 changed file with 16 additions and 10 deletions.
26 changes: 16 additions & 10 deletions JsonExcel.vue
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export default {
methods: {
async generate() {
let data = this.data;
if(this.fetch && !this.data)
if(typeof this.fetch === 'function' || !data)
data = await this.fetch();
if (!data || !data.length) {
Expand All @@ -104,7 +104,7 @@ export default {
return this.export(
this.jsonToXLS(json),
this.name,
"application/vnd.ms-excel"
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
);
},
/*
Expand Down Expand Up @@ -250,17 +250,23 @@ export default {
}
return parseData;
},
getValue(key, item) {
const field = typeof key === "object" ? key.field : key;
let indexes = field.split(".");
const field = typeof key !== "object" ? key : key.field;
let indexes = typeof field !== "string" ? [] : field.split(".");
let value = this.defaultValue;
if( indexes.length > 1 )
return this.getValueFromNestedItem(item, indexes);
if (!field)
value = item;
else if( indexes.length > 1 )
value = this.getValueFromNestedItem(item, indexes);
else
value = item[field];
if( key.hasOwnProperty('callback'))
return this.getValueFromCallback(item, key.callback)
value = this.getValueFromCallback(value, key.callback);
return this.parseValue(item[field]);
return value;
},
getValueFromNestedItem(item, indexes){
Expand All @@ -272,10 +278,10 @@ export default {
return this.parseValue(nestedItem);
},
async getValueFromCallback(item, callback){
getValueFromCallback(item, callback){
if(typeof callback !== "function")
return this.defaultValue
const value = await callback(item);
const value = callback(item);
return this.parseValue(value);
},
parseValue(value){
Expand Down

0 comments on commit 7296128

Please sign in to comment.