Angular - 如果>隐藏项目ng-repeat上的5

时间:2015-11-25 13:59:57

标签: javascript html angularjs

我有一个包含50个项目的过滤器列表。我只想显示5个项目并隐藏其余部分以制作“显示更多”按钮。

<ul>
    <li ng-repeat="a in filters.area">
         <input type="checkbox" ng-change="filter()" ng-model="a.checked"> {{ a.name }}
    </li>
</ul>
<span>SHOW MORE</span>

3 个答案:

答案 0 :(得分:3)

您可以在Angular中使用LimitTo

select CarrierPosition, COUNT(*) as FailCount
from tbl_0000000024,
     tbl_0000000025
where asictestdate >= DATEADD(hour,-6, getdate())
  and FK_AS0000000032 = fk_as0000000056
  and fk_as0000000046 = '135'
  and FailReason = '151'
  and tbl_0000000025.Status = ' Current'
group by CarrierPosition
Order by CarrierPosition

以下是JsFiddle

示例

答案 1 :(得分:2)

在AngularJS中使用// replace call to random colour code with this, and define a boolean in your class to use as a flag: if(!someFlag) { someFlag = YES; return [UIColor redColor]; } else { someFlag = NO; return [UIColor blueColor]; } 过滤器

limitTo

Documentation

你的例子就是这样:

{{ limitTo_expression | limitTo : limit : begin}}

答案 2 :(得分:1)

请查看此thread和此演示plunker

var i = 1;
var ToDoForm = React.createClass({

  getInitialState: function() {
    return {text: '', submittedValues: [{id: '000001', text: 'Rich'}, {id: '000002', text: 'Simon'}]};
  },
  handleChange: function(event) {
    this.setState({text: event.target.value});
  },
  handleSubmit: function(e) {
    e.preventDefault();

    var submittedValue = {text: this.state.text, id: i++};
    this.setState({submittedValues: this.state.submittedValues.concat(submittedValue)});
    this.setState({text: ''});
    console.log("ToDo: " + this.state.submittedValues);
  },

  render: function() {

    return (
        <div>
          <h1> todos </h1>

          <form className="todoForm" onSubmit={this.handleSubmit}>
            <input
                type="text"
                placeholder="Type out a task"
                value={this.state.text}
                onChange={this.handleChange}
                />
            <input
                type="submit"
                value="Submit todo"
                />
          </form>

          <h2> Data should appear here </h2>

          <ToDoList listItems={this.state.submittedValues}/>
        </div>
    );
  }
});