Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>There is no easy way to do it, because you are not supposed to perform that kind of logic in the view. Place your filter in the model or a controller before you render it.</p> <p>The one exception I can think of in this case is if you would like to limit the number of items to display. That might or might not be a suitable task for the view depending on the situation. </p> <p><strong>Examples:</strong></p> <p><strong>Keep the logic of a limit out of the view:</strong><br> - List of Question on Stack Overflow with paging (limit, offset, sorting)</p> <p><strong>Enforce a limit in the view:</strong><br> - A list of attached images for each question. Your mobile view only have room to show one per question. The view suitable for desktop have room for three. </p> <p>How to structure your application and where to place your logic is a debate with many opinions though. This style of separation is what I've been taught from experience and peers, but I am sure that there are many out there with different idéas. </p> <p>Here's a simple way to filter your data using underscore.js.</p> <pre><code> var videoContent = _.filter(contentMediaTypeList, function(mediaType) { return mediaType.mediaTypeName == "video"; }); </code></pre> <p>Working <code>JSFiddle</code>: <a href="http://jsfiddle.net/n98yW/" rel="nofollow">http://jsfiddle.net/n98yW/</a></p> <p>Or create a <code>closure</code> out of it for reusability</p> <pre><code>var mediaTypeFilter = function(mediaTypeName) { return function(contentMediaTypeList) { return _.filter(contentMediaTypeList, function(currMediaType) { return currMediaType.MediaTypeName == mediaTypeName; }); } }; </code></pre> <p>And use it like this</p> <pre><code>var videoFilter = mediaTypeFilter("video"); var videoContent = videoFilter(contentMediaTypeList); </code></pre> <p>Here's another <code>JSFiddle</code> for this solution using a closure: <a href="http://jsfiddle.net/GA55g/2/" rel="nofollow">http://jsfiddle.net/GA55g/2/</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.
 

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