I am trying to build something similar to planning poker and am very new to Knockout and was wondering if anyone could help me improve on my very crude start?
This is what I have so far:
HTML
Selected Card
CSS
.profile { width: 50px; height: 80px; color: #FFF; background: black; border: 1px solid #FFF; float: left; line-height:80px }
.highlight { background: yellow !important; border:1px solid #000; color: black; }
JavaScript/Knockout
function Step(number) {
this.active = ko.observable(false);
this.name = ko.observable( number);
}
var model = function () {
var items = ko.observableArray([new Step(1), new Step(2), new Step(3), new Step(5),new Step(8),new Step(13),new Step(20),new Step(40),new Step(100)]);
var selectedItems = ko.computed(function () {
return _.filter(items(), function (item) {
return item.active();
});
})
var clicked = function (item) {
items().forEach(function(item){ item.active(false) });
item.active(!this.active());
};
var save = function () {
alert("sending items \n" + ko.toJSON(selectedItems()));
}
return {
items: items,
selectedItems: selectedItems,
save: save,
clicked: clicked
}
}
ko.applyBindings(model);