Coffeescript + AngularJS循环将数据打印到网页

时间:2015-11-19 14:03:51

标签: html angularjs coffeescript

我是这项技术的新手,我遇到了一个我无法解决的问题。我想在我的系统中打印所有用户的一些属性。我使用data-ng-repeat来浏览用户,它适用于用户名。然而,其他属性会相互覆盖,因此最终会为所有用户显示相同的数据。后端函数loadMonthlyStats(mValue.date,user)工作正常并返回我期待的数据。问题可能在前端。知道如何更改前端代码以避免这种情况吗?

代码:

<div id="reports" class="panel" data-ng-show="displayReports">
  <div class="row">
    <div class="col-md-6">
      <ul class="list-group">
        <li class="list-group-item" ng-repeat="user in employees">{{user.getUsername()}}
          <tabset justified="true">
            <tab data-ng-repeat="mValue in monthvalues" data-heading="{{mValue.date | date : 'MMMM yyyy' }}"
                 data-select="loadMonthlyStats(mValue.date,user)">
              <br>
              <!-- next row is being displayed correctly -->
              User: {{user.get('username')}} <br>
              <!-- these rows keeps being overwritten -->
              Worked:{{mValue.monthTime | durationHumanize}} <br>
              Required:{{mValue.targetMonthTime | durationHumanize}} <br>
              {{mValue.completedPercent | number:2}} %
            </tab>
          </tabset>
        </li>
      </ul>
    </div>
  </div>
</div>

durationHumanize过滤器:

angular.module 'myWebApp'
  .filter 'durationHumanize', ->
    (duration) ->
      #duration is in seconds
      mduration = moment.duration(duration, 'seconds')
      hours = Math.floor(mduration.as('hours'))
      minutes = mduration.get('minutes')
      result = ''
      if hours < 10
        result += '0'
      result += hours + 'h '
      if minutes < 10
        result += '0'
      result += minutes + 'm'
      return result

0 个答案:

没有答案