【发布时间】:2015-07-09 19:31:45
【问题描述】:
我有一个下拉列表和一个 json 文件,我想使用下拉列表中的每个选项从 json 文件中加载两个不同的数据,但我不知道该怎么做。
这是我的下拉代码,我也从控制器中创建的 json 类型文件中获取下拉数据
<select ng-model="appointment" name="appointment-sch" ng-options="item as item.name for item in selectItemsFilterCriteria">
<option value="">Filter Criteria</option>
</select>
我正在像这样将选项下拉到控制器中
$scope.selectItemsFilterCriteria = [
{id:1 , name:"appointments scheduled"},
{id:2 , name:"fresh leads"}
];
我的 json 文件中有数据,现在我希望根据从下拉列表中选择的选项对我的数据进行排序,并将其显示到一个简单的表格中
这是我的服务
(function() {
'use strict';
angular
.module('n.lead-allocation')
.factory('factoryLeadAlloc',function($http) {
function fetchLeadRecord() {
return $http({
url: "../www/jsonFiles/leadAllocRecord.json",
method: "GET"
});
}
return{
fetchLeadRecord:fetchLeadRecord
}
});
})();
我将此服务调用到控制器中并将服务 json 数据存储到项数组中。
$scope.items = [];
factoryLeadAlloc.fetchLeadRecord().success(function(response) {
$scope.items = response;
$scope.search = function () {
$scope.filteredItems = $filter('filter')($scope.items, function (item) {
return searchMatch(item.name, $scope.query) || searchMatch(item.phoneNo, $scope.query);
//for(var attr in item) {
// if (searchMatch(item[attr], $scope.query))
//
// return true;
//}
//return false;
});
// take care of the
【问题讨论】:
-
你能分享代码吗,你是如何加载json数据的
-
好吧,这只是一个疯狂的猜测,我个人会在您的选择上使用 ng-change,因此每次值更改时都会调用您的更改函数,并且您只需过滤您的项目并创建数组/对象你的表格数据
-
我可以举一个例子,因为我是 Angular 新手,我不知道可用的全部选项
标签: javascript json angularjs drop-down-menu