2016-12-18 3 views
1

Ich arbeite an einem Projekt und ich bin Anfänger bei HTML, CSS, Javascript und eckig. Im mit API von einer Website mit Filmen und deren Daten in json und sortiert nach Seiten

{ 
"page": 1, 
"results": [ 
{ 
"poster_path": "/1yeVJox3rjo2jBKrrihIMj7uoS9.jpg", 
"popularity": 14.31312, 
"id": 1396, 
"backdrop_path": "/eSzpy96DwBujGFj0xMbXBcGcfxX.jpg", 
"vote_average": 8, 
"overview": "Breaking Bad is an American crime drama television series created and produced by Vince Gilligan. Set and produced in Albuquerque, New Mexico, Breaking Bad is the story of Walter White, a struggling high school chemistry teacher who is diagnosed with inoperable lung cancer at the beginning of the series. He turns to a life of crime, producing and selling methamphetamine, in order to secure his family's financial future before he dies, teaming with his former student, Jesse Pinkman. Heavily serialized, the series is known for positioning its characters in seemingly inextricable corners and has been labeled a contemporary western by its creator.", 
"first_air_date": "2008-01-19", 
"origin_country": [ 
"US" 
], 
"genre_ids": [ 
18 
], 
"original_language": "en", 
"vote_count": 858, 
"name": "Breaking Bad", 
"original_name": "Breaking Bad" 
}, 

ich es geschafft haben, den Fernseher auf dem Bildschirm zeigt aufzulisten, aber ich habe ein Problem, weil von Seiten variabel. Wenn ich $ http.get verwende, benutze ich diese URL https://api.themoviedb.org/3/tv/top_rated?api_key=ap_key&language=en-US&page=1, wie ändere ich Seite und Autorefresh-Seite, so dass es die Seite zwei auf Knopfdruck zeigt.

 Mpage=1; 
     TVpage=1; 

     nextM = function(){Mpage++;} 

     $http.get('https://api.themoviedb.org/3/movie/popular?api_key=040eb2b1bb7d1697319a08872e2578cb&page='+Mpage) 
     .success(function(data) { 
     $scope.Mresults = data.results; 
     }) 


     $http.get('https://api.themoviedb.org/3/tv/popular?api_key=040eb2b1bb7d1697319a08872e2578cb&page='+TVpage) 
     .success(function(data) { 
     $scope.TVresults = data.results; 
     }) 
+0

Zunächst einmal nicht jquery und Winkel mischen, wenn Sie wirklich wissen, was Sie tun und jQuery Plugins für Funktionen, die nicht in Winkelmodule verwenden. Es sind bereits zahlreiche Seitenmodule für eckige verfügbar, die Sie verwenden können – charlietfl

Antwort

0

Bitte überprüfen Sie das beigefügte Snippet. Es sollte Ihnen eine Idee geben, wie Sie dies erreichen können.

PS: Das Snippet wird nicht ausgeführt, da ich keine Winkelanweisungen ausgeführt habe. Aber ein einfaches Jquery-Snippet, um Ihnen eine Idee zu geben, wie Sie es zum Laufen bringen können.

$(function(){ 
 
    _pagination.initialize(); 
 
}); 
 

 
var _pagination = { 
 
    initialize: function(){ 
 
    $('.pagination').on('click', function(){ 
 
     var page = $(this).attr('id').split('_')[2]; 
 
     _pagination.getPageData(page); 
 
    }); 
 
    }, 
 
    getPageData: function(page){ 
 
    $http.get('https://api.themoviedb.org/3/movie/popular?api_key=040eb2b1bb7d1697319a08872e2578cb&page='+page) 
 
     .success(function(data) { 
 
     $scope.Mresults = data.results; 
 
     }) 
 
    } 
 
}
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script> 
 
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script> 
 
<button type="button" id="pagination_btn_1" class="pagination">1</button> 
 
<button type="button" id="pagination_btn_2" class="pagination">2</button> 
 
<button type="button" id="pagination_btn_3" class="pagination">3</button> 
 
<button type="button" id="pagination_btn_4" class="pagination">4</button> 
 
<button type="button" id="pagination_btn_5" class="pagination">5</button>