Reputation: 5774
I am working on a checkbox list which basically has group of clusters.. Structure is given below
Cluster 1 :
Cluster 2 :
Cluster 3 :
I want to build query like, selected items in same cluster will be joined by OR and selected items from different clusters will be joined by AND..
e.g. (Cluster1 Subitem 1 OR cluster1 subitem 2) AND (Cluster2 Subitem 3) AND (Cluster3 Subitem 1 OR cluster3 subitem 3)
In above example, selected items are subitem 1 and 2 in cluster1, subitem 3 in cluster 2 and subitem 1 and 3 in cluster3...
I have managed to achieved it with hardcoded values in this fiddle : http://jsfiddle.net/rahulrulez/8YfmW/3/
Code snippet -
switch (parent.Id()) {
case "IsIssue":
if (self.IsIssue.indexOf(item.Value()) == -1 && item.isChecked(false)) self.IsIssue.push(item.Value());
else self.IsIssue.remove(item.Value());
break;
case "Owner":
if (self.Owner.indexOf(item.Value()) == -1 && item.isChecked(false)) self.Owner.push(item.Value());
else self.Owner.remove(item.Value());
break;
case "Project":
if (self.Project.indexOf(item.Value()) == -1 && item.isChecked(false)) self.Project.push(item.Value());
else self.Project.remove(item.Value());
break;
}
Is there any way to optimize it if we are not sure about number if clusters we are getting from server as a response?
Thanks in advance, Rahul
Upvotes: 0
Views: 69
Reputation: 266
you can just bind your checkbox on isChecked observable :
<input type="checkbox" data-bind="attr : { value : Name}, checked: isChecked">
then create your query in your computed, here's a fiddler example : http://jsfiddle.net/RapTorS/PRV42/
Upvotes: 1