javascript - Check multiple checkboxes in knockout.js binded by JSON -


I am new to JSON and knockout I am facing a problem that I have a dataset in JSON For example, 10 bootens have been defined. E.g.

  IsHappy = true; IsSad = false; IsAngry = true;  

etc. My view model is made from JSON string, and I bind values ​​to the checkbox in such a way as: -

  & lt; Input type = "checkbox" data-bind = "checked: hashish" /> & lt; Input type = "checkbox" data-bind = "checked: ISAD" /> & Lt; Input type = "checkbox" data-bind = "checked: iseri" />  

I convert ViewModel back to JSON and save it on server to Ajax.

All this works well, but I can not understand that 'Select All' feature. I have read through the examples (online), in which to generate an observable array and see IsSelected (), but in my case how do I map different JSON attributes to the IsSelected () attribute, And similarly how IsSelected () the original JSON attribute can be viewed.

I just tried to set attr ('checked') using jquery, but doing so checks the box but ViewModel does not update, which means that when I call it back JSON Convert it to not been posted to the server side, no changes were found in it.

You can list them explicitly or you can collect them with objects. Kids).

Then when your all selected checkbook is checked, then you go through these arrays of these property names and set them accordingly newValue < / Code>:

  viewModel.allSelected.subscribe (function (newview) {var _this = this; // var checkboxes [['ishupi', 'iced', 'isjeri']; var Checkboxes = Object.keys (_thes) .filter (function (k) {Returns & endofs ('is') == 0;}); Ko.utils.arrayForEach (checkboxes, functions (banners) {_this [banner] (New line);});}, the Kenmodel);  

Demo


Comments

Popular posts from this blog

Pass DB Connection parameters to a Kettle a.k.a PDI table Input step dynamically from Excel -

multithreading - PhantomJS-Node in a for Loop -

c++ - MATLAB .m file to .mex file using Matlab Compiler -