-1

I'm pushing in a JSON structure some data and I have this issue as my structure should look at the next example:

{
  "data": {
           result: [{},{},{}]  
          }
} 

What I have instead is is the:

result: [{},{},{}]

I need to push this structure as data:result but no clue how to do it.

This is what I did until now:

var parent_uuid = node.parent.data.uuid;
    var subject_data = node.data.subject_data;

    result = []

    var keys = Object.keys(subject_data);
    for (var i = 0; i < keys.length; i++) {
      result.push({name: keys[i], label: keys[i], value: subject_data[keys[i]], type: "string", edit: false})
    }
    result.push({name: "enable", label: "enabled", value: true, type: "boolean", edit: true})

    _this.selectForm();
    _this.displayForm(parent_uuid, result);
str
  • 42,689
  • 17
  • 109
  • 127
Jakub
  • 2,367
  • 6
  • 31
  • 82
  • 1
    why not `{ "data": { result: result } } ` – xianshenglu Apr 12 '18 at 08:18
  • Please read [What is the difference between JSON and Object Literal Notation?](https://stackoverflow.com/questions/2904131/what-is-the-difference-between-json-and-object-literal-notation) – str Apr 12 '18 at 08:19

1 Answers1

0

As mentioned by @str, read the following: What is the difference between JSON and Object Literal Notation?

And to answer your question you can do the following:

_this.displayForm(parent_uuid, { "data": { "result": result } });

Kenny Alvizuris
  • 435
  • 4
  • 6
  • I did this but still, my structure is wrong. I wrote in the console this `result.data.leght` and result undefined. What I should have a structure like is in this past bin: https://pastebin.com/9VpHHBw1 @KennyAlvizuris – Jakub Apr 12 '18 at 08:45
  • @Jakub could try to do the following? `_this.displayForm(parent_uuid, { "data": { "result": result } });` – Kenny Alvizuris Apr 12 '18 at 08:51
  • still don't see the right structure as the one I posted before I see this now https://pastebin.com/AfH3G1rc There is no data still – Jakub Apr 12 '18 at 08:58
  • Then it's something else @Jakub is there a way I could take a look to the complete function? so I can give you a jsfiddle – Kenny Alvizuris Apr 12 '18 at 12:11
  • Great, I'm glad to hear. Thanks for the "up vote" ;) – Kenny Alvizuris Apr 12 '18 at 12:46