Dhana Dhana - 10 months ago 37
JSON Question

Unable to display names and perform edit for json data in angularjs?

I wanted to do some crud operations for my json data. But I am failing:

  1. to
    display the names
    (I am getting 0, 1 and 2 instead of my
    actual names:
    Main1, Main2

  2. on
    option: I am unable to get my dynamic filed options: it
    should display
    dynamic fields/values
    only and they can be
    edited/updated with new values

and hence if I click on
button it should redirect to my main page(it is working fine)

Note: on Edit screen: these field values should be editable/up-datable, for example if I select Main1(but it's displaying 0 instead of Main1 on my view currently)

"testkey01": "testkey01data",
"testkey02": 40,
"testkey03vals": [1, 1, 1]

and similarly for other names too.

Please let me know how can I do these and thanks in advance. Plnkr is created.

Answer Source

For the first part, the task could be achieved with the help of a function that you can declare inside your controller:

$scope.getKey = function(item) {
    return Object.keys(item)[0];

And then use it in HTML like this:


I've updated the plunker here.

LE: I've also updated the plunker to solve your edit problem. You were not aware that you had to put the key also. In all honesty your json is quite a mess. You'll still have to work some stuff out from that point on. I hope I helped you a bit at least. Good luck!