Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>If you want the visibility of those divs to change dynamically (which it seems that you might), you will want to to make isVisible a <a href="http://knockoutjs.com/documentation/computedObservables.html" rel="nofollow noreferrer">computedObservable</a>. That will make sure that the isVisible logic gets re-run when observables (that it depends on) change.</p> <p>it could return a string which you could bind you visibility to (data-bind="visible: isVisible() === 'Area'"), or you could create a different computed for each div if they are unrelated. (isAreaVisilbe, isBedroomVisible, ...) Your viewModel essentially turns into something like this:</p> <pre><code>function ViewModel() { var self = this; self.propertyTypeList = ko.observableArray(['Area', 'Bedroom', 'Other']); self.selectedPropertyType = ko.observable(""); self.visibleFeatures = ko.observableArray([]); self.visibleDiv = ko.computed(function () { //Your logic here return self.selectedPropertyType(); }); </code></pre> <p>I made a basic working example of what I think you are trying to make here <a href="http://jsfiddle.net/ZqWDS/5/" rel="nofollow noreferrer">http://jsfiddle.net/ZqWDS/5/</a> Had to change your viewModel to be a function so that the isVisible property can reference other properties. (<a href="https://stackoverflow.com/questions/14034476/how-to-reference-properties-of-current-object-in-js">How to reference properties of current object in JS</a>). And you can read the section titled 'A popular convention that simplifies things' on the knockout computedObservables page for more details about why I structured the viewModel constructor that way.</p> <p>I'm not sure what's causing your error at the top of the question. I pasted your code into a jsFiddle and it essentially worked (with a few minor syntax edits) <a href="http://jsfiddle.net/GBkdK/" rel="nofollow noreferrer">http://jsfiddle.net/GBkdK/</a></p> <p>If you are still having issues and want to provide some more context, I'm happy to help.</p> <p><strong>EDIT</strong> Sorry, I think I was wrong about isVisible needing to be a computed. It appears that it could just be a function like you originally had it. <a href="http://jsfiddle.net/ZqWDS/6/" rel="nofollow noreferrer">http://jsfiddle.net/ZqWDS/6/</a></p> <p><a href="https://stackoverflow.com/questions/6706281/knockoutjs-can-we-create-a-dependentobservable-function-with-a-parameter?lq=1">knockoutjs: can we create a dependentObservable function with a parameter?</a></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload