vue-json-excel icon indicating copy to clipboard operation
vue-json-excel copied to clipboard

Not accepting object property name with special character

Open violerine opened this issue 6 years ago • 4 comments

I have object property name for example "Queue No." with full-stop. In xls format it generates empty fields (all the values re missing) for that object property. Is it not allowed for object property name? Thanks

violerine avatar Feb 15 '19 09:02 violerine

Avoid using "." for object key in prop "fields" Maybe you want to process your data first~

JesseWeb avatar Mar 06 '19 10:03 JesseWeb

Avoid using "." for object key in prop "fields" Maybe you want to process your data first~

Why having "." in property name is considered to be wrong? Today I've experienced this weird (for me) behaviour. I could not understand why having "." is wrong so I decied to jump into source code and I found that is done with purpose, which still is not clear for me.

There is sample of this problem: https://codesandbox.io/s/vue-template-1p4k2

    getValue(key, item) {

      const field = typeof key   !== "object" ? key : key.field;
      let indexes = typeof field !== "string" ? []  : field.split("."); //here
      let value   = this.defaultValue;

      if (!field)
	      value = item;
      else if( indexes.length > 1 )
        value = this.getValueFromNestedItem(item, indexes); // and then here
      else
        value = this.parseValue(item[field]);
      
      if( key.hasOwnProperty('callback'))
        value = this.getValueFromCallback(value, key.callback);
      
      return value;
    }, 

So let's see what "getValueFromNestedItem" method does:

  getValueFromNestedItem(item, indexes){
      let nestedItem = item;
      for (let index of indexes) {
        if(nestedItem)
          nestedItem = nestedItem[index];
      }
      return this.parseValue(nestedItem);
    }, 

So if you have field named "Que. No" it tries to find in the same item propety named "Que" and then property " No" inside "Que". But next thing is that the same function "getValue" will be fired on property Que, which is object. It's really confusing for me.

I think "." in property name is ok, the real issue is that the code is trying to get nested data. I feel like if there is case with nested data, then you should process it and always treat propety name just as name, not the definition where data is stored somewhere else in object.

Or maybe I'm just missing something?

kosa127 avatar Jun 27 '19 22:06 kosa127

It will be nice if allow any field name for me.

Object key string should be replaced by other syntax.

vikyd avatar Aug 27 '19 01:08 vikyd

I agree with @kosa127, this part of code is not properly written. It should accept dot as part of key and add new boolean property called "enableNestedItem" to enable that part of code. or maybe let users select the nested char by themselves not just dot.

phattanun avatar Apr 12 '22 08:04 phattanun