Monday, 15 July 2013

javascript - How to update a JSON Object that is represented in a form -


I have a JSON object that I used to make a form. This JSON object is parsed by knockoutJs.

Now, when I am modifying the form, I want to update the JSON object according to the modifications made in the form. The thing is that I do not already know what the form will be like, but I know in the JasonOn object that the field needs to be updated.

I do not know what is the best way to proceed. I know that I have changed something every time, but it can rebuild JSON objects, but it seems like a bad idea and a tiring process.

Is each JSON object field an easy way to make items in knockoutJS?

I felt something interesting with this line:

/ P>

  Lt; Input type = "text" data-bind = "value: $ data.value, attr: {disabled: $ data.disabled}" />   

I'm reaching the value directly from the array ($ data.value). There is a way in HTML to beat in order to bind this particular feature in the array. I know that if the array is reordered then everything will get messy, but since I know that only one thing that can change is this property, am I ready to take this risk?

There is a way to manually say that when this value changes to change it in the array such as

  data-bound = "on change: $ data" Value = this.value "   

Do each JSON object field in Knock OutJs An easy way to create an item?

Yes, if I think what you want to do right now, your visual model does not have value observations and automatically updates as form cost change Will not be done. There is a plugin to handle this mapping. Example: To use a .map

To create a visual model through the mapping plugin, replace the .mapping .jpg Creating visual modules in the code above with the function:

var viewmodel = ko.mapping.fromJS (data);

This creates automatically ignored properties for each asset on the data. Then, every time you get new data from the server, you can update all the properties on the viewfinder module in one step by calling ComoProMJS function again:

Ko.mapping.fromJS (Data, ViewModel);

Hope it helps.

No comments:

Post a Comment