【问题标题】:Unable to segregate comments with their respective answers无法将评论与其各自的答案分开
【发布时间】:2016-12-18 01:36:09
【问题描述】:

我已经在表单中看到了我的问题的解决方案,并尝试使用嵌套的ng-repeat。我的项目由一个问题及其相关答案组成,每个答案由 cmets 组成。在使用嵌套 ng-repeat 时,我可以为每个问题打印相同的评论数组。 结果数组:

我已经试过了:

 <div class="col-md-10 col-md-push-1" ng-repeat="x in question.answercomments track by $index">
        <div ng-repeat="y in x">
                {{y.comment}}
        </div>

</div>

最终得到:

所以,我想在他们各自的答案上有 cmets。

【问题讨论】:

  • 在您的示例中很难理解数据及其结构。如果数据和您尝试过的内容,您可以创建一个带有示例的 jsfiddle 吗?

标签: html angularjs ng-repeat


【解决方案1】:

这是我解决此问题的尝试:https://plnkr.co/edit/UrjCzU4ocBxwFNwcVedU

您可以尝试以下方法:

<div ng-repeat="answer in question.answer">
  <h1 ng-bind-html="answer.answer"></h1>
  <!-- loop over the comments attached to this particular answer -->
  <div class="col-md-10 col-md-push-1" ng-repeat="x in answer.answercomments"> 
    <!-- now output the comment -->
    {{x.comment}}
  </div>
</div>

我认为,问题在于您没有遍历附加到特定答案的 cmets,然后输出 cmets

【讨论】:

  • 非常感谢!我没有循环附加到特定答案的 cmets。我在循环中从头开始再次循环。
猜你喜欢
  • 2022-06-10
  • 2021-11-24
  • 2017-09-21
  • 1970-01-01
  • 2014-03-18
  • 2013-07-10
  • 1970-01-01
  • 2013-12-31
  • 2022-07-08
相关资源
最近更新 更多