Angularjs 在固定位置重复项目
我有一个ng repeat指令,我想在固定的索引位置显示不同的对象值 数据: 我想让它表现得像 ng重复: 1:(show cat.name:“早餐”)只应显示在索引0处 2:(不显示包含“早餐”、“晚餐”的项目) 3:(不显示包含“早餐”的物品)(显示类别名称: “晚餐”)-仅在占有指数3处显示“晚餐” 4:(不显示包含“早餐”、“晚餐”的项目) 5:(不显示包含“早餐”、“晚餐”的项目) 等等Angularjs 在固定位置重复项目,angularjs,angularjs-ng-repeat,Angularjs,Angularjs Ng Repeat,我有一个ng repeat指令,我想在固定的索引位置显示不同的对象值 数据: 我想让它表现得像 ng重复: 1:(show cat.name:“早餐”)只应显示在索引0处 2:(不显示包含“早餐”、“晚餐”的项目) 3:(不显示包含“早餐”的物品)(显示类别名称: “晚餐”)-仅在占有指数3处显示“晚餐” 4:(不显示包含“早餐”、“晚餐”的项目) 5:(不显示包含“早餐”、“晚餐”的项目) 等等 我应该如何管理它?orderBy过滤器将实现这一点,但您需要帮助 我会给每一个cat项目一个显示顺
我应该如何管理它?orderBy过滤器将实现这一点,但您需要帮助 我会给每一个cat项目一个显示顺序,因为它需要一些东西 那就
<ul>
<li ng-repeat="x in data.recipe.cat | orderBy:orderMeals">
{{x.name}}
</li>
</ul>
请注意,我已将displayOrders添加到您的配方对象()试试这个
<script>
var app = angular.module('myApp', []);
app.controller('myCtrl', ['$scope', function($scope) {
$scope.json = {
"recipe": {
"id":"0001",
"name":"soup",
"cat":[{"name":"dinner"}, {"name":"lunch"}, {"name":"breakfast"}]
}
};
$scope.json.recipe.cat.reverse();
}]);
var-app=angular.module('myApp',[]);
app.controller('myCtrl',['$scope',函数($scope){
$scope.json={
“配方”:{
“id”:“0001”,
“名称”:“汤”,
“猫”:[{“名字”:“晚餐”},{“名字”:“午餐”},{“名字”:“早餐”}]
}
};
$scope.json.recipe.cat.reverse();
}]);
.html
这里:{t.name}
请参阅写入自定义筛选器。
var app = angular.module('myapp', []);
app.controller('myCtrl', function($scope, $timeout) {
$scope.data = {
"recipe": {
"id": "0001",
"name": "soup",
"cat": [{
"name": "dinner", displayOrder: 2
}, {
"name": "lunch", displayOrder: 1
}, {
"name": "breakfast", displayOrder: 0
}]
}};
$scope.orderMeals = function(item) {
console.log('item', item);
return item.displayOrder;
}
});
<script>
var app = angular.module('myApp', []);
app.controller('myCtrl', ['$scope', function($scope) {
$scope.json = {
"recipe": {
"id":"0001",
"name":"soup",
"cat":[{"name":"dinner"}, {"name":"lunch"}, {"name":"breakfast"}]
}
};
$scope.json.recipe.cat.reverse();
}]);
<body ng-app='myApp' ng-controller='myCtrl'>
<div ng-repeat ="t in json.recipe.cat" ng-if="t.name != 'breakfast' && t.name != 'dinner'">
here : {{t.name}}
</div>