如今,我用这名JSON,用KO绘图皮gin,并用工作罚款:
{
"Controls": [
{
"Fields": [
{
"Name": "emailField",
"Text": "email",
"Visible": true
},
{
"Name": "hiddenField",
"Text": "text",
"Visible": true
}
],
"Name": "form2",
"Type": "Form"
},
{
"Data": [
[
"Federico Aloi",
20
],
[
"Andres Lopez",
31
],
[
"Pablo Perez",
32
]
],
"Fields": [
{
"Name": "nameField",
"Text": "Nombre",
"Visible": true
},
{
"Name": "ageField",
"Text": "Edad",
"Visible": true
}
],
"Name": "datagrid1",
"Type": "Datagrid"
}
],
"Name": "pagina1",
"Title": "Probando el KO"
}
现在我的要求是“部分更新”。 在我愿意这样做的时候,一些情景是:
- I need to change the Data array in the second control.
- I need to update only one Control and not the whole Page (this is the class I m serializing, the root in this JSON).
- I need to add another Control to my Page.
也许还有另一个工作要做,将原物体重新编号为ko.mapping.toJS(viewModel)
,加以修改,然后重新绘制。 但我认为,你会做得更好。
<>光线> 我尝试了ko.mapping. fromJS(updatedControl, viewModel.Controls(0)
,但这里是我的法典:
function (control) {
$.getJSON($.format( api/control/{0}/{1} , viewModel.Name(), control.Name()), function (response) {
ko.mapping.fromJS(response, viewModel.Controls()[0]);
});
},
{
"Fields": [
{
"Name": "emailField",
"Text": "email",
"Visible": true
},
{
"Name": "hiddenField",
"Text": "text",
"Visible": true
}
],
"Name": "form2",
"Type": "Form"
}
<><><>>>>> http://jsfiddle.net/faloi/4FcAy/10/“http://jsfiddle.net/faloi/4FcAy/10/。