如何正确地将ng-repeat项作为参数传递给函数?我正在显示相关的html和js以及它给出的错误。
HTML:
<div class="swiper-slide" data-ng-repeat="items in (ctrl.cur_level || ctrl.first_level)">
<div class = "item" data-ng-repeat="item in items" data-ng-click="!ctrl.isWorkDay(item.lane.title)||ctrl.select(item)" data-ng-disabled="isWorkDay(item.lane.title)" >
<div class="{{ctrl.workingDayClass(item.lane.title)}}" >
<button>{{ item.num }}</button>
<span data-ng-if="item.lane" class="title">{{ item.lane.title }}</span>
</div>
</div>
</div>
JS:
isWorkDay: (title) ->
enabled = true
d = new Date();
n = $this.weekday[d.getDay()];
if(n=="Sunday" or n=="Saturday")
if(isInArray(title, $this.freeServices))
enabled = false
else
if(title == "Дежурный врач")
enabled = false
console.log("item_inner "+$this.item_inner)
return enabled
isInArray: (value, array) ->
array.indexOf(value) > -1;
workingDayClass: (title)->
console.log("title "+title)
item_inner = "item_inner"
d = new Date();
n = $this.weekday[d.getDay()];
if(n=="Sunday" or n=="Saturday")
if(isInArray(title, $this.freeServices))
item_inner = "item_inner_disabled"
else
if(title == "Дежурный врач")
item_inner = "item_inner_disabled"
return item_inner
错误:
[$ interpolate:interr]无法插值: {{ctrl.workingDayClass(item.lane.title)}} ReferenceError:isInArray is 未定义
答案 0 :(得分:1)
使用 $ this.isInArray 代替 isInArray
此
if(isInArray(title, $this.freeServices))
应该是
if($this.isInArray(title, $this.freeServices))
干杯!