javascript - 收集重复不起作用

标签 javascript angularjs ionic-framework

我在 Collection Repeat 中遇到问题。这是我的 Controller 代码:

    .controller('RescheduleCtrl', function($scope){
    this.photos = [];
      for (var i = 0; i < 100; i++) {
        var w = 100 + Math.floor(Math.random() * 200);
        w -= w % 5;
        var h = 150 + Math.floor(Math.random() * 100);
        h -= h % 5;
        this.photos.push({
          width: w,
          height: h,
          src: "1995"
        });
      }


    })

这是 View 文件中的代码:

 <ion-scroll direction="x" class="available-scroller">
  <div class="photo" collection-repeat="photo in photos"
     item-height="250" item-width="photo.width + 30">
 {{photo.src}}
  </div>
</ion-scroll>

我收到错误:collection-repeat expected attribute collection-item-width to be a expression that returns a number (in pixels) or percentage.

最佳答案

问题是你没有在 HTML 上绑定(bind) photos 查看你的 Controller 代码告诉你正在使用 controllerAs 语法。所以如果你有 ng-controller="RescheduleCtrl as reschedule" 那么你可以在 html 上获取 photos 对象作为 reschedule.photos

标记

<ion-scroll direction="x" class="available-scroller">
  <div class="photo" collection-repeat="photo in reschedule.photos"
     item-height="250" item-width="photo.width + 30">
 {{photo.src}}
  </div>
</ion-scroll>

Working Codepen

关于javascript - 收集重复不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30002702/

相关文章:

javascript - 一个文本框值在另一个文本框中

javascript - less 文件的语法验证器

javascript - 如果我在 Kriskowal 的 q 中多次拒绝/解决会发生什么?

angularjs - [Angular, Jersey]为什么我必须使用 jersey 在 $http 中指定应用程序名称

加载 View 时angularjs清除历史记录

PHP/JavaScript OnMouseOver 链接不工作

javascript - Angularjs 基于下拉范围的搜索过滤器

javascript - 对齐屏幕 ionic html右下角的按钮

html - 将图标放在工具栏的最左边

angular - 我的拦截器上未定义构造函数变量(Angular 8)