Skip to content

Instantly share code, notes, and snippets.

@cleytonferrari
Created September 19, 2012 12:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cleytonferrari/3749447 to your computer and use it in GitHub Desktop.
Save cleytonferrari/3749447 to your computer and use it in GitHub Desktop.
Usando Knockout js com checkboxes
<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>
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