0

ジャーニーを検索する AngularJS アプリがあります。問題の一部では、地域ごとに利用可能なすべての国を表示しようとしています。国をクリックすると、機能が実行されなければならないという考え方です。しかし一向に火がつかない…

何か助けはありますか?

意見

<div id="headersearch" ng-controller="ProductSearchController">
    <div id="headersearchContainer">
        <input id="tripchoise" class="field" type="text" placeholder="Hoe ver wil je gaan?" ng-model="country" ng-change="switchView('countries')" ng-blur="switchView('')" ng-focus="switchView('countries')" />
        <div id="triptypechoise">
            <div class="triptype" ng-class="{active: filter=='single'}" title="Singlereizen" ng-click="switchFilter('single')"><img src="/Resources/Images/Layout/singlereis.png" alt="Singlereizen" /></div>
            <div class="triptype" ng-class="{active: filter=='custom'}" title="Maatwerkreizen" ng-click="switchFilter('custom')"><img src="/Resources/Images/Layout/maatwerk.png" alt="Maatwerkreizen" /></div>
            <div class="triptype" ng-class="{active: filter=='group'}" title="Groepsreizen" ng-click="switchFilter('group')"><img src="/Resources/Images/Layout/groepsreis.png" alt="Groepsreizen" /></div>
        </div>
        <div id="tripdeparturedatechoise" class="field arrow">
            {{date}}
        </div>
    </div>
    <div id="headersearchButton">
        <a href="#" class="bookbutton"><span>ZOEK</span></a>
    </div>
    <div class="clear"></div>
    <input type="text" class="datepicker datehide" id="searchdepartureDate" ng-model="date" datepicker/>
    <div id="searchList" ng-class="{hide:view==''}">
        <div class="loadingproducts" data-ng-show="loading">Loading products...</div>
        <article class="searchentry" ng-show="view=='countries'">
            <div class="" ng-repeat="region in regions">
                <p>{{region.Name}}</p>
                <ul>
                    <li ng-repeat="country in region.Countries">
                        <a ng-click="test()">{{country.Name}}</a>
                    </li>
                </ul>
            </div>
        </article>
    </div>
</div>

コントローラ

SearchApp.controller("ProductSearchController", function ($scope, $http) {
    $scope.date = "Vertrek";
    $scope.filter = "single";
    $scope.view = "";
    $scope.country = "";
    $scope.switchFilter = function (filter) {
        if ($scope.filter != filter) {
            $scope.filter = filter;
            $scope.search();
        }
    }
    $scope.switchView = function (view) {
        if ($scope.view != view)
            $scope.view = view;
        if ($scope.view != "" && $scope.view != "countries")
            $scope.search();
    }
    $http.post("/AVProductList/GetCountriesByRegionAsync")
        .success(function (response) {
            $scope.regions = response.regions;
    });
    $scope.search = function () {
        $scope.loading = true;
        $http.post("/AVProductList/SearchProductsHeader?view="+ $scope.view +"&filter=" + $scope.filter, { SearchParameters: {Country: $scope.country}})
          .success(function (data) {
              if ($scope.filter == "custom")
                  $scope.trips = data.results;
              else {
                  if ($scope.view == "trips")
                      $scope.trips = data.grouped.RoundtripgroupCode.doclist.docs;
                  else if ($scope.view == "departures")
                      $scope.trips = data.response.docs;
              }
          });
    };
    $scope.changeDate = function () {
        if (isValidDate($scope.date)) {
            $scope.view = "departures";
            $scope.search();
        }
        else { 
            $scope.date = "Vertrek";
            $scope.view = "trips";
        }
    }
    $scope.selectCountry = function (name, code) {
        $scope.countrycode = code;
        $scope.country = name;
        $scope.view = isValidDate($scope.date) ? "departures" : "trips";
        $scope.search();
    }
    $scope.test = function () {
        alert("Hoi");
    }


});

JSON結果の例

$http.post("/AVProductList/GetCountriesByRegionAsync")
        .success(function (response) {
            $scope.regions = response.regions;
    });

{
  regions:[
  {
    Name:"Asia",
    Countries: 
    [
      {
         Name: "China",
         Code: "CH"
      }
      ,...
    ]
  }  
  ,...
  ]
}
4

1 に答える 1

1

私はばかげた間違いを犯しました:

「tripchoise」の ngBlur は、ngClick の前に起動されました。

于 2013-10-31T12:56:21.003 に答える