1

I am using printJs library for printing in properties I added JSON object properties its working fine, but if that JSON object contains one more JSON object inside it is showing [object object]. Can anyone tell me the solution?

 PrintJS({

  printable: printIndexes,
  properties: ['reporter', 'entryTime', 'exitTime', 'status'],

  type: 'json',
  gridHeaderStyle: 'color: red;  border: 2px solid #3971A5;',
  gridStyle: 'border: 2px solid #3971A5;',
  header: 'List of master index'

enter image description here

Please see this image it is showing like [object object] there I want to display name.

Antikhippe
  • 6,316
  • 2
  • 28
  • 43
Sasidhar
  • 11
  • 1

2 Answers2

1

You can tell PrintJS which property in the nested object that should be printed. For example:

 printJS({
  printable: printIndexes,
  properties: ['reporter.name', 'entryTime', 'exitTime', 'status.value'],
  type: 'json',
  gridHeaderStyle: 'color: red;  border: 2px solid #3971A5;',
  gridStyle: 'border: 2px solid #3971A5;',
  header: 'List of master index'
});

Here is an example fiddle printing data from nested objects:

https://jsfiddle.net/crabbly/bLq52fyu/

crabbly
  • 5,106
  • 1
  • 23
  • 46
0

traverse the object inner deep for example:

user:{
    name:'xxx',
    address:{
              building:{
                           no:64,
                           street:corinder
                        },
              city:'texas'
             }
       }

You can traverse by user.address.building.no it will shown 64