Use the KO binding data column example:
1. First apply for V,T,T2 three auxiliary methods, easy to debug. The mapping condition when declaring ViewModel and loading data mapping
2. First use Ko.mapping.fromJS () to turn the original JS object into the ViewModel in Ko and use Ko.applybindings () to activate the knockout
3. The following lines of code are written within the Ajax success callback function. That is: use result. Data to update the ViewModel, here is actually the updated users array, the update process by the rules in mapping for each object under the array to add 4 additional dependency properties dependent observables.
The last sentence is somewhat difficult to understand, can be combined with the following several of the console is good to understand. A. Comparing 1 and 4, you can see that the user object in Figure 4 has 4 more attributes than 1, and that 4 objects can be bound to HTML like other properties. In this way, we have more flexibility when we bind at the front desk.. B. Look at figure 3 again, when using Ko.mapping.toJS () to turn ViewModel into a JS object, these 4 objects are not in it.
CombineTake a look at the example in the code above. 1. The ISVIP in the JSON to my background represents whether the user is a VIP, the bool format, and I'm now going to bind it to the radio buttons. But the parameters required in the radio buttons binding of KO are strings. Therefore, each time you update the list, add a temporary VIP property for each object for the page display, instead of running to the background to modify the returned data source because the data is not in the wrong format. 2. When I edit a user on the page, use theKo.mapping.toJS () converts the user (Ko object) to a JS (JSON) object, which can then be submitted directly to the background using the Ajax post.
4. The following is the final display, in order to be simple, page binding is only bound to PhoneNumber and look. (Cell phone Number column bindingPhoneNumber, the Avatar column is bound by the look)
From for notes (Wiz)
Binding data list using mapping plugin in Knockoutjs