通过Angular中的http.get访问唯一的JSON记录

时间:2016-06-14 08:23:17

标签: javascript angularjs json angular-ngmodel angular-http

我知道需要访问JSON中显示的各个记录,而不是从一个JSON文件中收集我的订单数据。是否可以调整http.get请求,使其具有变量选项(对于订单号)并更改ng-repeat以显示单个记录。

因此,在list.html上,如果我搜索订单参考号12145,它将从http://example.com/api/booking/get/guest/12145提取数据,list.html和detail.html中的ng-repeat输出将显示确切的顺序。

我认为ng-model搜索查询需要附加到http.get url?

以下是Plunker中的代码: https://plnkr.co/edit/eS28uBh2y1tmbAP597zM?p=catalogue

和一个显示我想要做的事情的gif(搜索顺序ref,追加到url,获取数据) http://i.imgur.com/6RVsHof.gif

  // Ionic Starter App

  // angular.module is a global place for creating, registering and retrieving Angular modules
  // 'starter' is the name of this angular module example (also set in a <body> attribute in index.html)
  // the 2nd parameter is an array of 'requires'
  angular.module('starter', ['ionic','ngCordova'])

  .run(function($ionicPlatform) {
    $ionicPlatform.ready(function() {



      if(window.cordova && window.cordova.plugins.Keyboard) {
        // Hide the accessory bar by default (remove this to show the accessory bar above the keyboard
        // for form inputs)
        cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);

        // Don't remove this line unless you know what you are doing. It stops the viewport
        // from snapping when text inputs are focused. Ionic handles this internally for
        // a much nicer keyboard experience.
        cordova.plugins.Keyboard.disableScroll(true);
      }
      if(window.StatusBar) {
        StatusBar.styleDefault();
      }
    });
  })

  .config(function($stateProvider, $urlRouterProvider) {

    $stateProvider
      .state('tabs', {
        url: '/tab',
        abstract: true,
        templateUrl: 'templates/tabs.html'
      })
      .state('tabs.home', {
        url: '/home',
        views: {
          'home-tab' : {
           templateUrl: 'templates/home.html'
          }
        }
      })
      .state('tabs.list', {
        url: '/list',
        views: {
          'list-tab' : {
           templateUrl: 'templates/list.html',
           controller: 'ListController'
          }
        }
      })
      .state('tabs.detail', {
        url: '/list/:aId',
        views: {
          'list-tab' : {
           templateUrl: 'templates/detail.html',
           controller: 'ListController'
          }
        }
      })

        // if none of the above states are matched, use this as the fallback
        $urlRouterProvider.otherwise('/tab/home');

  })

  .controller('ListController', ['$scope', '$http', '$state','$cordovaBluetoothSerial', '$window', '$location', function($scope, $http, $state, $cordovaBluetoothSerial, $window, $location) {
          $http.get('http://example.com/api/booking/get/guest/{{ query }}').success(function(data) {
            $scope.orders = data;
            $scope.whichorder = $state.params.aId;

          })

          $scope.orders = [];

           function onPay(order) {
           var itemsArr = [];
           var invoice = {};
           var myItems = {};
           var myItem = {};
           //var order = $scope.orders[];

           myItem['name'] = "Sphero";
           myItem['description'] = "A robotic ball that can be controlled via apps";
           myItem['quantity'] = "1.0";
           myItem['unitPrice'] = order.bkor_subtotal;
           myItem['taxRate'] = '0.0';
           myItem['taxName'] = 'Tax';
           itemsArr.push(myItem);
           myItems['item'] = itemsArr;

           invoice['itemList'] = myItems;
           invoice['paymentTerms'] = 'DueOnReceipt';
           invoice['currencyCode'] = 'GBP';
           invoice['discountPercent'] = '0';
           invoice['merchantEmail'] ="email@email.com";
           invoice['payerEmail'] = 'foo@bar.com';

           var returnUrl = order.bkor_seatcount;
           var retUrl = encodeURIComponent(returnUrl + "?{result}?Type={Type}&InvoiceId={InvoiceId}&Tip={Tip}&Email={Email}&TxId={TxId}");
           //var pphereUrl = "paypalhere://takePayment/?returnUrl={{returnUrl}}&invoice=%7B%22merchantEmail%22%3A%22{{merchantEmails}}%22,%22payerEmail%22%3A%22{{payerEmails}}%22,%22itemList%22%3A%7B%22item%22%3A%5B%7B%22name%22%3A%22{{name}}%22,%22description%22%3A%22{{description}}%22,%22quantity%22%3A%221.0%22,%22unitPrice%22%3A%22{{price}}%22,%22taxName%22%3A%22Tax%22,%22taxRate%22%3A%220.0%22%7D%5D%7D,%22currencyCode%22%3A%22{{currency}}%22,%22paymentTerms%22%3A%22DueOnReceipt%22,%22discountPercent%22%3A%220.0%22%7D";
           var pphereUrl = "paypalhere://takePayment/v2?returnUrl=" + retUrl;
           pphereUrl = pphereUrl + "&accepted=cash,card,paypal";
           pphereUrl = pphereUrl + "&step=choosePayment";
           pphereUrl = pphereUrl + '&invoice=' + escape(JSON.stringify(invoice));
           console.log(pphereUrl);

           return pphereUrl;

           }

          $scope.pay = function (order) {
          var url = onPay(order);
          window.open(url, "_system");
          }
  }]);

0 个答案:

没有答案