【问题标题】:show and hide div from a repeat重复显示和隐藏 div
【发布时间】:2015-01-07 15:20:52
【问题描述】:

我有一个标题并在重复时对标题进行评论。

我想要做的是,首先隐藏帖子下方的所有输入,然后单击“在下方显示输入”按钮,仅显示该帖子的输入。基本上是一个切换,但在重复中。

$scope.posts = [{"_id":"5","post":"second post","created_at":"2015-01-07T07:11:37.477Z"},{"_id":"542","post":"first post","created_at":"2015-01-07T07:11:30.922Z"}]

<div class="col-sm-12 margin-top-10" data-ng-repeat="post in posts track by $index">
        <h4>{{post.post}}</h4>
        <button type="button" class="pull-right btn btn-xs">
            show input below
        </button>
        <h6 data-ng-repeat="comment in post.comments track by $index">{{comment}}</h6>
        <form name="form.comment">
            <input class="col-sm-12" type="text" name="commentText" ng-model="commentText" ng-keyup="$event.keyCode == 13 ? takeComment(post._id, commentText) : null" required>
        </form>
        <br>    
        <br>
        <br>
    </div>

【问题讨论】:

    标签: angularjs


    【解决方案1】:
    $scope.posts = [{"_id":"5","post":"second
    post","created_at":"2015-01-07T07:11:37.477Z"},{"_id":"542","post":"first
    post","created_at":"2015-01-07T07:11:30.922Z"}]
    
    <div class="col-sm-12 margin-top-10" data-ng-repeat=
    "post in posts track by $index">
        <h4>{{post.post}}</h4><button class="pull-right btn btn-xs" type=
        "button" ng-click="post.show = !post.show">show input below</button> <--- add ng click
    
        <h6 data-ng-repeat="comment in post.comments track by $index">
        {{comment}}</h6>
    
        <form id="form.comment" name="form.comment" ng-show="post.show"> <--- add ng show
            <input class="col-sm-12" name="commentText" required="" type=
            "text">
        </form><br>
        <br>
        <br>
    </div>
    

    【讨论】:

      猜你喜欢
      • 2020-05-25
      • 2021-12-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-04-04
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多