Last active
November 9, 2015 16:06
-
-
Save wbsimms/9adb799090a93eed580e to your computer and use it in GitHub Desktop.
KO Dropdown
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
function productSelectorViewModel(data) { | |
var self = this; | |
self.dataTier0 = ko.observableArray(data); | |
self.dataTier1 = ko.observableArray(); | |
self.dataTier2 = ko.observableArray(); | |
self.tier0Selection = ko.observable(); | |
self.tier1Selection = ko.observable(); | |
self.tier3Selection = ko.observable(); | |
var tier3sub; | |
function subscribeTier3() { | |
tier3sub = self.tier3Selection.subscribe(function (e) { | |
var event = e; | |
var selection = self.tier3Selection().Label; | |
}); | |
} | |
subscribeTier3(); | |
self.tier0Selection.subscribe(function () { | |
tier3sub.dispose(); | |
$.each(self.dataTier0(), function (index, item) { | |
if (item.Label === self.tier0Selection().Label) { | |
self.dataTier1(item.Children); | |
if (tier3sub.isDisposed === true) | |
subscribeTier3(); | |
return; | |
} | |
}); | |
}); | |
self.tier1Selection.subscribe(function () { | |
tier3sub.dispose(); | |
$.each(self.dataTier1(), function (index, item) { | |
if (item.Label === self.tier1Selection().Label) { | |
self.dataTier2(item.Children); | |
if (tier3sub.isDisposed === true) | |
subscribeTier3(); | |
return; | |
} | |
}); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment