当前位置: 动力学知识库 > 问答 > 编程问答 >

javascript - Adding data to a existing data source kendo

问题描述:

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.

分享给朋友:
您可能感兴趣的文章:
随机阅读: