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    scope.events = [{     '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 scope.events | filter:scope.query"> {{event.date}} 

And currently using this to get films:

<div ng-repeat="film in event.films | orderBy:name"> {{film.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 film.name---> </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 scope.events, (event) ->       if scope.orderList == 'start_date'         # sort by date         scope.orderList = 'start_date'         scope.events =  $filter('orderBy')(scope.events, start_dates, reverse)       else if val == 'film'         # sort by film         scope.orderList = 'film'         # Logic to sort by film.name 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?

Replay

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

Related post

iOS development

Android development

Python development

JAVA development

Development language

PHP development

Ruby development

search

Front-end development

Database

development tools

Open Platform

Javascript development

.NET development

cloud computing

server

Copyright (C) avrocks.com, All Rights Reserved.

processed in 0.295 (s). 12 q(s)