【发布时间】:2014-12-19 17:57:24
【问题描述】:
我是 Angular 的新手,我遇到了过滤功能的问题。
首先,内容是从 json 文件中提取的。很简单:
[
{
"id":"0",
"animal":"cat",
"breed":"siamese",
"name":"kevin",
"photo": "/images/kevin.jpg"
},
{
"id":"1",
"animal":"dog",
"breed":"pug",
"name":"barney",
"photo": "/images/barney.jpg"
}
]
等等。
页面上的html。导航点来自他们自己的 json 文件,与数据无关,只是为了创建菜单并传递值:
<ul>
<li ng-repeat="item in animal_data">
<a href="" ng-click="filterData(item.animal)">{{item.animal | uppercase}}</a>
</li>
</ul>
<ul>
<li ng-repeat="item in breed_data">
<a href="" ng-click="filterData(item.breed)">{{item.breed | uppercase}}</a>
</li>
</ul>
过滤器脚本:
$scope.filterData = function(item)
{
var passFilterType = $filter('filterType')($scope.original_data, item);
if(passFilterType.length > 0)
{
$scope.isLoading = true;
$scope.isSuccessful = false;
$scope.percentLoaded = 0;
$scope.thumbnails = passFilterType;
loadImages();
}else{
console.log("error");
}
}
function loadImages()
{
var passImages = getImages();
if(passImages.length > 0)
{
preloader.preloadImages(passImages).then(handleResolve, handleReject, handleNotify);
}
}
我的计划是将 LI 转换为复选框,然后将我带到需要帮助的地步。有没有办法利用我已经设置的东西来过滤多种动物和品种?
感谢任何可以提供帮助的人。
【问题讨论】:
标签: javascript jquery json angularjs filtering