Here is a subset of the markup I am using:
<div id="item_one"></div>
<div id="item_two"></div>
<div id="item_three"></div>
<p id="result_one">0</p>
<p id="result_two">0</p>
<p id="result_three">0</p>
The desired behaviors are:
- When you click a div, the corresponding text of the p tag is toggled from 0 to 1.
- The text of the p tags is to be concatenated into a string, e.g., click the second item and the resulting string would be “010”.
- There is an array of eight items, with binary strings as the key. As clicks are made, the selected item in the array changes.
This seems like a good use of knockout, but I am a complete noob. How do I set up the proper dependencies?
Here is a sample for one way to do it: http://jsfiddle.net/rniemeyer/XqDsy/
For convenience, I created a little “binaryObservable” that exposes a toggle function.
Then the HTML might look like: