how to update json data,

how to update json data,

SrilakshmiSrilakshmi Posts: 35Questions: 6Answers: 0
edited September 2014 in General

Hi, I have the following json data,

dataSource: [{
                id: 1, text: "root1", expanded: true, spriteCssClass: "rootfolder", items: [
                    {
                        id: 2, text: "folder1", expanded: true, spriteCssClass: "folder", items: [
                            { id: 3, text: "c1", spriteCssClass: "html" },
                            { id: 4, text: "c2", spriteCssClass: "html" },
                            { id: 5, text: "c3", spriteCssClass: "image" }
                        ]
                    },
                    {
                        id: 6, text: "folder2", expanded: true, spriteCssClass: "folder", items: [
                            { id: 7, text: "c4", spriteCssClass: "image" },
                            { id: 8, text: "c5", spriteCssClass: "pdf" },
                        ]
                    },
                    {
                        id: 9, text: "folder3", expanded: true, spriteCssClass: "folder", items: [
                            { id: 10, text: "c6", spriteCssClass: "pdf" },
                            { id: 11, text: "c7", spriteCssClass: "pdf" },
                            { id: 12, text: "c8", spriteCssClass: "pdf" }
                        ]
                    }
                ]
            }]

now, how do I find the row which has id 8 and change its text to cChanged using jquery.
looking forward for a reply,
Srilakshmi.

Replies

  • allanallan Posts: 63,687Questions: 1Answers: 10,500 Site admin

    Why do you specifically want to use jQuery for this? What would be the advantage over using a simple for loop in Javascript and checking what the ID is for each object, which is how I would do it myself?

    Also I should point out that this is a general Javascript question and therefore off topic for this forum which is specifically for DataTables. However, as I say, a simple for loop with an if statement would do it.

    Allan

This discussion has been closed.