Created
September 19, 2012 12:46
-
-
Save cleytonferrari/3749447 to your computer and use it in GitHub Desktop.
Usando Knockout js com checkboxes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<ul data-bind="template: { name: 'choiceTmpl', foreach: choices, templateOptions: { selections: selectedChoices } }"></ul> | |
<script id="choiceTmpl" type="text/html"> | |
<li> | |
<input type="checkbox" data-bind="attr: { value: $data.id }, checked: $item.selections" /> | |
<span data-bind="text: $data.descricao"></span> | |
</li> | |
</script> | |
<hr /> | |
<div data-bind="text: ko.toJSON(selectedChoices)"></div> | |
<hr /> | |
<div data-bind="text: selectedChoicesDelimited"></div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var viewModel = { | |
choices: [{id:1,descricao:"Leitura"},{id:2,descricao:"Escrita"},{id:3,descricao:"Gravação"}], | |
selectedChoices: ko.observableArray(["2"]) | |
}; | |
viewModel.selectedChoicesDelimited = ko.dependentObservable(function() { | |
return this.selectedChoices().join(","); | |
}, viewModel); | |
ko.applyBindings(viewModel); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment