我要求TheMovieDB中的内容在我的网站上显示它(标题,图像,发布日期),并将该内容存储在我的数据库中。我想知道是否有可能按日期订购。
我知道那里| orderBy:'date'"
但我不确定如何在我的网站上使用它。
我希望按日期订购两种情况。
第一种情况是,当用户执行搜索操作时,他们可以输入电影标题,我的搜索功能将从TheMovieDB中检索所有标题(和发布日期)并将其显示在ul
中。
%div{"ng-controller" => "searchCtrl", :id => "container_search"}
%input{"ng-change" => "search(searchquery)", "ng-model" => "searchquery", "ng-model-options" => "{ debounce: 500 }", :id => "search_input", :placeholder => "Search a movie!", "ng-keyup" => "clear_results()"}
%ul#showresults
%li.search_results{"ng-repeat" => "movie in movieList"}
.addmovie{"ng-click" => "addMovie()"}
%span
Add Movie
%img.poster{"ng-src" => "http://image.tmdb.org/t/p/w500/{{ movie.poster_path }}"}
%span.title
{{ movie.original_title }}
%span.release
{{ movie.release_date }}
TheMovieDB http请求的输出如下所示,
angular.callbacks._6({"page":1,"results":[{"adult":false,"backdrop_path":"/jSNIAKD5pCyhjgJL9HZ3hsu19yD.jpg","genre_ids":[28,12,80],"id":206647,"original_language":"en","original_title":"SPECTRE","overview":"A cryptic message from Bond’s past sends him on a trail to uncover a sinister organization. While M battles political forces to keep the secret service alive, Bond peels back the layers of deceit to reveal the terrible truth behind SPECTRE.","release_date":"2015-10-26","poster_path":"/zHx5KaKaQdZZnEUgtjcIdNcB3ka.jpg","popularity":1.279592,"title":"SPECTRE","video":false,"vote_average":7.0,"vote_count":61}],"total_pages":1,"total_results":1})
第二种情况是当用户检查他的首页时,它会显示他添加到他页面的所有电影标题。
%div{"ng-repeat" => "movie in movies", :class => "movie_container"}
%h2
{{ movie.release_date }}
%img.poster{"ng-src" => "{{ movie.image }}"}
.movie-info
%h2
{{ movie.title }}
%a{"ng-click" => "deleteMovie(movie)"}delete
这些是在创建它们时排序的,而不是在它们被释放时排序。我的JSON文件的输出是这个,
{"id":51,"created_at":"2015-08-27T13:05:19.074Z","updated_at":"2015-08-27T13:05:19.074Z","user_id":1,"image":"http://image.tmdb.org/t/p/w500//uereni1nSrWb6OWiJhK7FrW4pcd.jpg","title":"\n Batman v Superman: Dawn of Justice\n ","release_date":"\n 2016-03-25\n "}]
答案 0 :(得分:0)
不要将日期用作字段im orderBy
的字符串getter。我建议你创建一个自定义函数,将元素转换为值。可以通过在日期对象中转换JSON日期字符串(例如,使用momentjs)来获得此值,然后以秒为单位获取绝对时间。