我正在开展一个项目,并且我是html,css,javascript和angular的初学者。我使用来自带有电影的网站的API,他们的数据是json并按页面排序
{
"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"
},
我设法在屏幕上列出电视节目,但由于页面变量我有问题。当我使用$ http.get时,我使用此网址https://api.themoviedb.org/3/tv/top_rated?api_key=ap_key&language=en-US&page=1,如何更改页面和自动刷新页面,以便在按钮单击时显示第2页。
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 :(得分:0)
请检查附带的代码段。它应该让你了解如何实现这一目标。
PS:该片段不会运行,因为我还没有执行角度指令。但是一个简单的jquery片段可以让您了解如何使其工作。
$(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>
&#13;