简体   繁体   English

收集重复无效

[英]Collection repeat is not working

I have a problem in Collection Repeat. 我在“收集重复”中遇到问题。 Here is my controller code: 这是我的控制器代码:

    .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"
        });
      }


    })

This is the code in view File: 这是视图文件中的代码:

 <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>

I got Error: collection-repeat expected attribute collection-item-width to be a an expression that returns a number (in pixels) or percentage. 我收到错误消息:collection-repeat期望属性collection-item-width是一个返回数字(以像素为单位)或百分比的表达式。

The problem is you are not binding photos on HTML looking at you controller code tells that you are using controllerAs syntax. 问题是您没有在HTML上绑定photos ,而是看着控制器代码告诉您正在使用controllerAs语法。 So if you have ng-controller="RescheduleCtrl as reschedule" then you can get photos object on html as reschedule.photos 因此,如果您有ng-controller="RescheduleCtrl as reschedule"那么您可以将HTML上的photos对象作为reschedule.photos

Markup 标记

<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 工作码笔

If you want to push something you have to add this things --> " " 如果要推送某些内容,则必须添加这些内容-> " "

Soo.. your script would be like this: 如此..您的脚本将是这样的:

.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,  /* Here are the edits */
          "height": h,
          "src": "1995"
        });
      }


    })

I hope this worked for you 我希望这对你有用

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM