javascript - How do I get set of data from JSON click on next and previous button -
i developing hybrid mobile app of angular , ionic. sample data getting :
$scope.data = [{ "pid": 108, "name": "demo", "tid": 20, "date": "2016/00/29" }, { "pid": 98, "name": "sports demo1", "tid": 20, "date": "2016/06/02" }, { "pid": 98, "name": "sports demo2", "tid": 20, "date": "2016/06/02" }, { "pid": 98, "name": "sports demo3", "tid": 20, "date": "2016/06/02" }, { "pid": 98, "name": "sports demo4", "tid": 20, "date": "2016/06/02" }]
1st page html :
<ion-content class="" padding="true"> <ul ng-repeat="datasch in data"> <li class="item" style="border-width: 0px;"> <div class="item" style="border-width: 0px; padding : 1px;">{{datasch.name}}</div> <div class="item" style="border-width: 0px; padding : 1px;">{{datasch.date}}</div> </li> </ul> </ion-content>
2nd page html :
<ion-content class="" padding="true"> <div>detail 1</div> <div>detail 2</div> </ion-content> <ion-footer-bar align-title="left" class="bar-assertive"> <button ng-click="next()">next</button> <button ng-click="previous()">previous</button> </ion-footer-bar>
in first page clicking on "li" based on "pid" opening 2nd page details. in 2nd page footer have option move next , previous data there itself. how next or previous data show on 2nd page.
ex: clicked on second element @ first page , got data name "sports demo1" on 2nd page. once click on next button data should "sports demo2" or click on previous button data should "demo".
html : <a ng-click="opendetails(passing_only_selected_data);">open data</a> <div> <h4 >{{alldata.name}}</h4> <h4 >{{alldata.name1}}</h4> <h4 >{{alldata.date}}</h4> </div> <ion-footer-bar class="bar-assertive" > <button ng-disabled="mydisabled1" ng-click="previousitem();"> previous </button> <button ng-disabled="mydisabled2" ng-click="nextitem();"> next</button> </ion-footer-bar> js $scope.opendetails = function(data){ var fullarraylength = $scope.mydata.length - 1; $scope.data = data; var index= $scope.mydata.indexof(data); $scope.index = index; if(fullarraylength == $scope.index){ $scope.mydisabled2 = true; }else if($scope.index == 0){ $scope.mydisabled1 = true; }else{ $scope.mydisabled1 = false; $scope.mydisabled2 = false; } var alldata = $scope.mydata[$scope.index]; $scope.alldata = alldata; } $scope.opendetails1 = function(arrayindex){ var fullarraylength = $scope.mydata.length - 1; if(fullarraylength == arrayindex){ $scope.mydisabled2 = true; }else if(arrayindex == 0){ $scope.mydisabled1 = true; } $scope.data = $scope.data; var alldata = $scope.mydata[arrayindex]; $scope.alldata = alldata; } $scope.previousitem = function(){ $scope.opendetails1($scope.index - 1); $scope.index--; } $scope.nextitem = function(){ $scope.opendetails1($scope.index + 1); $scope.index++; }
Comments
Post a Comment