javascript - AngularJS - 使用 Mysql 进行过滤

标签 javascript filter resources angularjs

我尝试根据邮政编码在静态(非谷歌) map 上设置标记。
这是我的 html 代码:

<div ng-controller="DealerMarkerListCtrl">
    <a href="#/dealer/{{marker.id}}" class="marker" style="left:{{marker.left}}px;top:{{marker.top}}px" ng-repeat="marker in dealer|zipFilter:countryLookup"></a>
</div>  

现在我尝试显示按邮政编码和国家/地区过滤的所有标记,以下是下拉列表:

<input type="text" name="plz" placeholder="PLZ (z.B 80469)" class="plz" ng-model="zipCodeLookup">
<select name="drop" tabindex="1" class="drop" id="dropcountry" ng-model="countryLookup" ng-options='option.value as option.name for option in typeOptions'>
</select>

我得到了以下过滤器:

app.filter("zipFilter", function() { return function(markers, country, zip) {
    var retMarkers = [];
    for(var i = 0, len = markers.length; i < len; ++i) {
        var singleMarker = markers[i];
        if(singleMarker.land == country) {
            retMarkers.push(singleMarker);
        }
    }
    return retMarkers;
}});

主要问题是:
我进行了外接圆搜索,获得了用户邮政编码周围 20(公里/英里)范围内的所有邮政编码。这工作正常。当我直接访问框架(不在 Controller 内)时,我得到这样的 json:

{"plz":["44787","44789","44791","44793","44795","44797","44799","44801","44803","44805","44807","44809","44866","44867","44869","44879","44892","44894","45525","45527","45529","45549"]}  

邮政编码“45525”。

现在我需要显示此邮政编码数组中的所有标记(经销商)。
需要将过滤器中的 zip 参数与国家/地区参数一起发送到“区域搜索”功能“files/framework/umkreis/:zip/:country”以获取该区域的 zip json。
之后我需要检查一些标记是否在这个 json 中并过滤它们。

我只是不知道如何将这些东西构建到我的过滤器中。你能帮我解决这个问题吗?非常感谢。

其他有用信息:
路线和服务:

app.factory('dealerService', ['$resource', '$http', '$rootScope', function($resource, $http, $rootScope){
    return {
    //the resource provider interacting with the PHP backend
        api: 
        $resource('files/framework/dealer/:id', {}, {
            update: {method:'PUT'}
        }),
    }
}])

app.config(['$routeProvider', function($routeProvider) {
  $routeProvider.
      when('/dealer/:id', {templateUrl: 'files/tpl/dealer-details.html', controller: 'DealerDetailsCtrl'}).
      otherwise({redirectTo: '/dealer'});
}]); 

“Slim”框架获取区域邮政编码的路线是:

files/framework/umkreis/45525/DE
or
files/framework/umkreis/:zip/:country

最佳答案

您似乎正在尝试根据表单中的两个字段更新 map 上的标记:“zipCodeLookup”和“countryLookup”。

<input ... ng-model="zipCodeLookup" ... />
<select ... ng-model="countryLookup" ... ></select>

标记显示在以下 Controller 中:

<div ng-controller="DealerMarkerListCtrl"></div>  

并且您正在使用此路由从 PHP 服务器收集 JSON

files/framework/umkreis/:zip/:country

您需要做的是在“DealerMarkerListCtrl” Controller 中指定一个函数,该函数将获取邮政编码和国家/地区,并使用服务器中的新 JSON 更新经销商。

$scope.updateDealer = function(zip, country) { 
    $http.get('files/framework/umkreis/'+ zip + '/' + country).
    success(function(data) { 
        $scope.dealer = data; 
    }); 
}

有了这个之后,您可以添加 ng-submit<form>包含将调用此函数的输入,

<form ng-submit="updateDealer(zipCodeLookup, countryLookup)"> ... </form>

确保<form>位于正确的 Controller 内部以查看新创建的函数。每当用户提交此表单时,它都会调用您的 PHP 服务器,获取 JSON,并更新经销商数组。

关于javascript - AngularJS - 使用 Mysql 进行过滤,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14142440/

相关文章:

java - 多个列表或列表和 getSublist() (Java)

c# - 找不到适合指定区域性的任何资源

resources - 如何管理应用资源?

c# - 全局常量的正确使用方法

javascript - Ionic Angular 元素中未加载样式表

javascript - 有什么方法可以检测 DOM 树中不直接来自 React 的更改吗?

javascript - 如何删除数组中具有相同键值对的对象

javascript - 为什么手动设置时间与当前时间不同

amazon-web-services - AWS CloudSearch:如何使用_score作为过滤器

list - 使用过滤器迭代列表