Skip to content

Instantly share code, notes, and snippets.

@cleytonferrari
Created September 19, 2012 13:21
Show Gist options
  • Save cleytonferrari/3749656 to your computer and use it in GitHub Desktop.
Save cleytonferrari/3749656 to your computer and use it in GitHub Desktop.
Usando knockout js com checkboxes sem template
<ul data-bind="foreach: items">
<li>
<input type="checkbox" data-bind="attr: { value: id }, checked: $root.checked" />
<span data-bind="text: descricao"></span>
</li>
</ul>
<hr/>
<div data-bind="text: ko.toJSON($root)"></div>​
var ViewModel = function() {
var self = this;
this.items = ko.observableArray([
{ id: "1", descricao: "Leitura" },
{ id: "2", descricao: "Gravação" },
{ id: "3", descricao: "Escrita" },
{ id: "4", descricao: "Nenhuma" }
]);
this.checked = ko.observableArray(["2","4"]);
};
ko.applyBindings(new ViewModel());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment