[Refer to the updates below]
I am trying to make a knockout depending on the choice, it is intended to select a “product” by these attributes, for example, a product can have a “size” and a “material”, if I select a “size”, a knockout script will make a request for a backend and get which material "is available for the selected size, in other words, if an attribute is selected, other attributes are filtered out to show only available values (" all sizes ": 1,2, 3,4,5," aluminum ": 1,4).
The list of attributes is completely dynamic, there are about 80 attributes that can be associated with products in any way.
Is there a “best practice” for this situation?
I am trying to solve it with code like this, before I have time:
var ViewModel = function(data) { var self = this; self.data = data; self.attributes = ko.observableArray(); self.data.forEach(function(item, i, a) {
UPDATE 1: With the Dnyanesh link to ko.subscribe (), I achieved these results, so far not everything is all right, but progress:
http://jsfiddle.net/xwild/65eq14p3/
UPDATE 2: In the end, it was resolved using knockout.reactor and knockout.mapping plugins.
https://stackoverflow.com/a/3186269/how-to-setup-statement-in-javascript/232837#816623