- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个包含多个对象的列表,一开始我只想加载其中的一些。我查看了ng-repeat
语句,但我需要有这样的结构:
<table class="table table-hover table-hidden">
<thead>
<tr>
...
</tr>
</thead>
<tbody>
<tr ng-repeat-start="object in objects | filter:query | orderBy:predicate:reverse" ng-init="isCollapsed=true">
...
</tr>
<tr ng-repeat-end class="more">
...
</tr>
</tbody>
</table>
我尝试在 ng-repeat-start
中应用语句 limitTo,如下所示:
<tr ng-repeat-start="object in objects | filter:query | orderBy:predicate:reverse| limitTo: limit" ng-init="isCollapsed=true">
在 Controller 上我写道:
$scope.limit = 10;
$scope.incrementLimit = function () {
$scope.limit += 10;
};
通过点击超链接来调用函数incrementLimit
<a href ng-click="incrementLimit()">more</a>
页面加载时,对象列表被实例化并填充(包含所有元素)。
按照我一开始的方法,加载并正确显示前 10 个元素,当我单击“更多”时,变量 $scope.limit
会增加,但页面上没有任何反应。谁能解释一下为什么?
最佳答案
limitTo
在 ng-repeat-start
看看这个
var app = angular.module('myApp', []);
app.controller('Controller', function ($scope) {
$scope.limit = 1;
$scope.incrementLimit = function () {
$scope.limit += 1;
};
$scope.data = [{
title: 'Foo',
text: 'Lorem'
}, {
title: 'Bar',
text: 'Iste'
}, {
title: 'Jon',
text: 'Fat'
}, {
title: 'Los',
text: 'Ice'
}]
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.21/angular.min.js"></script>
<div ng-app='myApp' ng-controller="Controller">
<table border="2" class="table table-hover table-hidden">
<thead>
<tr>...</tr>
</thead>
<tbody>
<tr ng-repeat-start="object in data | filter:query | orderBy:predicate:reverse| limitTo: limit" ng-init="isCollapsed=true" ng-bind="object.title">...</tr>
<tr ng-repeat-end class="more">...</tr>
</tbody>
</table>
<a href="#" ng-click="incrementLimit()">more</a>
</div>
关于javascript - AngularJS ng-repeat-start 与 limitTo 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30027804/
因此,我正在尝试以预定义的量在 Angular limitTo 上实现一种切换效果。我的意思是传入的数据具有 bool 值“showMore”。如果为真,我所在的重复将被限制为 5,否则根本没有限制。
我正在尝试在 Angular2 的字符串上运行 limitTo 管道: {{ item.description | limitTo : 20 }} 我收到以下错误: The pipe 'limitTo
我可以将 limitTo 与条件一起使用吗?它的文档仅显示了简单的用法。 假设我想显示名为 car 的项目的 2 个结果: $scope.items = [ {"name":"laptop",
我正在尝试结合使用 Angular 的 limitTo 和过滤器,但它似乎无法正常工作。我希望能够在搜索框中输入一个值,然后按搜索。之后,我想通过在过滤器框中输入数字并按应用过滤器来限制显示的结果。但
我猜想下面代码的输出应该是text 3和text 4,但是没有得到正确的结果。那里的代码有问题吗? HTML Hello {{name}} text {{$index+1}}
我有一个名为 articles 的对象数组,每个对象都包含一个名为 category 的字符串数组。每篇文章在 DOM 中都用一个 ngRepeat 指令表示,其中包含第二个 ngRepeat 指令来
$scope.items = [ {"name":"laptop","color":"green"}, {"name":"shoe","color":"blue"}, {"na
我有以下指令( sales.jade ): div(ng-repeat='product in products') div.col-md-4 button.btn.btn-b
据我了解,在 AngularJS 中,名为“limitTo”的过滤器用于限制数据。 假设我们有 100 条记录,并且我们使用以下方法将数据限制为 10 条记录limitTo 过滤器。 现在如何显示剩余
AngularJS userData.success(function (userdataobject) { $scope.catadata = userdatao
我想使用 AngularJS 来显示打乱后的列表——但只显示前几个元素。目前,我在 HTML 模板中同时执行改组和限制,如 this fiddle 中所示。 : {{value}} 这工作
我的模型从 json 文件加载他的数据。 { "soonepisodes":{ "limit":"3", "oderby":"percent" },
所以我有 ng-repeat 输出的列表指令,我有过滤器 | limitTo: amount就在上面。 amount变量根据用户屏幕尺寸而变化。它正在正确更改,但更新变量时列表不会重新呈现。 如何强制
这里使用 angularjs 1.3: 我在表行中使用限制,如下例所示: {{r.id}} {{r.name}} 100"> Prev Next 我有很多数据,因此我
我在 AngularJS 中有一些绑定(bind),我想限制显示的字符长度。当您只有简单的文本内容时,这是一个非常简单的问题。 但是,我有包含 HTML 标签的文本: $scope.text = "E
我尝试在表格的行中仅显示 10 个字符,为此我使用了 limitTo: 10 但它不起作用, HTML 代码: User ID
我正在使用 ng-repeat 显示结果集中的所有项目。我有一个自定义搜索框,它通过自定义过滤器过滤掉结果。我现在需要添加分页,但我还需要结果集中的所有项目都可以搜索,无论分页如何。这是代码: 根据
这jsbin展示了我正在尝试做的事情。 我遇到的问题是,当将 limitTo 过滤器与 ng-repeat 一起使用时。当 limitTo 变量设置为较高值时,它们会按自上而下的顺序进行动画处理,但是
我目前遇到 ng-repeat 问题,并限制了 View 中显示的元素数量。我想知道这是否与嵌套循环有关。这是代码: {{ (psp.promptname) ? psp.p
我是 AngularJS 1.4.x 的新手。 {{ limitTo_expression | limitTo : limit : begin}} ng-repeat='项目中的项目 | limitT
我是一名优秀的程序员,十分优秀!