【问题标题】:Append search query (ng-model) to JSON http.get request将搜索查询(ng-model)附加到 JSON http.get 请求
【发布时间】:2016-10-19 04:49:00
【问题描述】:

我希望将搜索查询附加到 JSON http.get 请求,然后在收到数据时显示下面的订单(之前我已经访问了所有订单)

我正在使用并假设 ng-model 是这里的解决方案,但我很难用我当前的代码成功地进行 JSON 调用。

搜索页面(列表)

  <ion-header-bar class="bar-dark">
          <h2 class="title">Order List</h1>
  </ion-header-bar>
          <div class="bar bar-subheader item-input-inset bar-light">
            <label class="item-input-wrapper">
              <i class="icon ion-search placeholder-icon"></i>
              <input type="search" ng-model="query" placeholder="Search">
            </label>
          </div>

        <ion-content class="has-subheader">
          <ion-list>
            <ion-item ng-show="query" ng-repeat="order in orders | filter:query" class="item-thumbnail-left item-text-wrap"
            href="#/tab/list/{{order.bkor_user}}">
              <h2>Production Name: {{order.bkev_name}}</h2>
              <h3>Seatcount: {{order.bkor_seatcount}}</h3>
              <h2>Order Subtotal: £{{order.bkor_subtotal}}</h2>
            </ion-item>
          </ion-list>
        </ion-content>

控制器

    .controller('ListController', ['$scope', '$http', '$state','$cordovaBluetoothSerial', '$window', '$location', function($scope, $http, $state, $cordovaBluetoothSerial, $window, $location) {
              $http.get('http://example.co.uk/bookingref/get/host/{{ query }}').success(function(data) {
                $scope.orders = data;
                $scope.query = query;
                //console.log($scope.orders);
                //console.log(JSON.stringify(config));
                $scope.whichorder = $state.params.aId;
                //console.log($scope.whichorder);


              })

我想我也必须编辑我的 ng-repeat,因为它是一个订单而不是一系列订单

【问题讨论】:

    标签: javascript angularjs json angular-ngmodel


    【解决方案1】:

    您应该通过将参数连接到 URL 字符串来将参数附加到字符串。

    $http.get('http://example.co.uk/bookingref/get/host/'+ $scope.query)
    

    【讨论】:

    • 这会产生白屏,控制台错误显示“app.js:74 Uncaught SyntaxError: Invalid or unexpected token”
    • @merch89 我认为你对$scope.query没有任何价值
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-11-29
    • 2016-04-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多