Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <pre><code>var results = self.resultCollection(); self.isModelValid = $.grep(results, function(n){return n}).length == results.length; </code></pre> <p>If the length of the filtered array returned by <code>$.grep</code> is the different from the original array, that means that at least one of the item is <code>false</code>. When they aren't the same, <code>self.isModelValid</code> will also be <code>false</code>, creating the effect you want.</p> <hr> <h2>Explanation</h2> <pre><code>$.grep(results, function(n){return n}) </code></pre> <p><code>$.grep</code> removes all <code>false</code> values and returns a new array using the filter <code>return n</code> (only returning true items).</p> <pre><code>$.grep(results, function(n){return n}).length == results.length </code></pre> <p>The new array's length is then compared to the original array's length. If they are different, that means that at least one item is <code>false</code> and removed. If their lengths are the same, this will returns <code>true</code>. <code>false</code> if they are different.</p> <pre><code>self.isModelValid = ... </code></pre> <p>The boolean is then assigned to <code>self.isModelValid</code>.</p> <hr> <p><code>$.grep</code> works, but it might not be the best practice in your case. jQuery will try to evaluate the whole array and returning a new one, increasing the performance cost. Use <a href="https://stackoverflow.com/a/17007211/283863">Blender</a>'s code if your array only contains booleans.</p> <p>On the other hand, if your array contains multiple types and you are already using jQuery, this might be the best way to do it. </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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      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