Вопрос

I'm in a process of implementing kendo grid with complex json. Everything renderes well but I need to add new Item to the existing datasource.Here is my json

Json

    {
        "id": "1",
        "EPF": "1000",
        "Name": "Chinthaka",
        "Components": [
            {   
                "Component": "Back Part",
                "Style": "Style",
                "StyleOperation": "Style Operation",
                "PCS": "30",
                "TotalPCS": "120"
            },
            {   
                "Component": "Back Part",
                "Style": "Style",
                "StyleOperation": "Style Operation",
                "PCS": "130",
                "TotalPCS": "160"
            }

        ]
    }

So I need to add a new Componet to the existing component Now I have 3 components and it should display under the same level

{ "Component": "Back Part", "Style": "Style", "StyleOperation": "Style Operation", "PCS": "80", "TotalPCS": "10" }

If anyone can help me on this that would be great

Это было полезно?

Решение

Simply push the new component into the array and use your current rendering code.

var data = {
    "id": "1",
    "EPF": "1000",
    "Name": "Chinthaka",
    "Components": [
        {   
            "Component": "Back Part",
            "Style": "Style",
            "StyleOperation": "Style Operation",
            "PCS": "30",
            "TotalPCS": "120"
        },
        {   
            "Component": "Back Part",
            "Style": "Style",
            "StyleOperation": "Style Operation",
            "PCS": "130",
            "TotalPCS": "160"
        }

    ]
}

data.Components.push({
    "Component": "Back Part",
    "Style": "Style",
    "StyleOperation": "Style Operation",
    "PCS": "80",
    "TotalPCS": "10"
})

Другие советы

Either do another read to the server with datasource. If you're not reading from the server get the index of currently components and specify the next after it with data you have, do a sync of the datasource component and possibly you'll have to redraw/refresh the component to display the new data.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top