Sort by other arrays/objects which have relationships in AngularJS

I have some arrays but want to sort using different filters. These arrays are all apart of one array, but I've separated them out and want to sort each one according to how one is sorted. Hope this makes sense. Basically the Events array is the base array and actually carries all the data that scope.films, scope.genres, and scope.dates carries... Films is extracted and put into its own array. Dates is taken from Events, and Genre is taking from Films. Here is some code before I continue:

  scope = this = [{     'films' : [{               'name': 'Film Name 1',               'genre': 'Horror'               }]     'date': '12/23/16'   }]    scope.films = [{     'name' : 'Film Name 1'     'genre': 'Horror'   }]    scope.genres = [{     'genre': 'Horror'   }]    scope.dates  = [{     'date': '12/23/16'   }] 

I'm displaying it using this:

<div ng-repeat-start="event in | filter:scope.query"> {{}} 

And currently using this to get films:

<div ng-repeat="film in event.films | orderBy:name"> {{}} 

My end goal is to be able to sort this data using a dropdown:

<select ng-model="scope.orderList">   <option value="date">Date</option>   <option value="genre">Genre</option>   <option value="film">Film</option><!--- this is> </select> 

And in my controller I have something like this so far:

  scope.orderList = 'start_date'    $scope.$watch angular.bind(scope, () -> return scope.query), (val) ->     _.each, (event) ->       if scope.orderList == 'start_date'         # sort by date         scope.orderList = 'start_date' =  $filter('orderBy')(, start_dates, reverse)       else if val == 'film'         # sort by film         scope.orderList = 'film'         # Logic to sort by in scope.films       else if val == 'genre'         # sort by genre         scope.orderList = 'genre'         # Logic to sort by genre in scope.genre         return 

I'm at a loss. Is there another way to sort by these relationships using a filter?


Category: javascript Time: 2016-07-28 Views: 0

Related post

iOS development

Android development

Python development

JAVA development

Development language

PHP development

Ruby development


Front-end development


development tools

Open Platform

Javascript development

.NET development

cloud computing


Copyright (C), All Rights Reserved.

processed in 1.545 (s). 13 q(s)