javascript - Filtering a List via a Sidebar -


there 2 lists of items. 1 blog posts, , 1 authors.

var app = angular.module("blog", []);  app.controller('postctrl', function($scope) {   $scope.posts = <%= @posts.to_json.html_safe %>;   $scope.authors = <%= @authors.to_json.html_safe %>; }); 

the information provided through database via rails. if don't know rails, assume have been given big chunk of json work with.

now, list blog posts:

<div id="blog-posts" ng-controller="postctrl">   <article class="post" ng-repeat="post in posts">     <h1> {{ post.title }} </h1>     <small> {{ post.author }} on {{ post.created_at }} </small>     <p> {{ post.body }} </p>   </article> </div> 

and decide make aside within #blog-posts div (so within postsctrl) list authors:

<aside>   <h2> authors </h2>   <ul>     <li ng-repeat="author in authors">       {{ author.name }}     </li>   </ul> </aside> 

its nice you're listing , displaying authors, want allow people filter based on author.

key question: how 1 filter blog posts when clicking on author?

hint: when user clicks on author (ngclick), put author in variable, can use filter posts list.


Comments

Popular posts from this blog

c++ - OpenCV Error: Assertion failed <scn == 3 ::scn == 4> in unknown function, -

php - render data via PDO::FETCH_FUNC vs loop -

The canvas has been tainted by cross-origin data in chrome only -