5

我正在尝试向我的一个模板添加少量逻辑(请不要责骂我将逻辑放入视图中的错误)并且很难获得正确的 hamlc 语法。

我正在迭代一个集合并想跳过另一个集合中存在的元素

直接的咖啡脚本看起来像:

for artwork in artworks
  unless _.find(cart_items, (ci) ->
    ci.id == artwork.product_code
      alert 'artwork not in cart'

我正在努力:

- for artwork in artworks
  - unless _.find(cart_items, (ci) -> | # < multiline, right?
    ci.id == artwork.product_code
    - alert 'artwork not in cart'

我得到了一些关于:

Block level too deep in line undefined

有任何想法吗?TIA,比利

4

1 回答 1

1

通过将闭包放在同一行上,我能够使其工作:

- for artwork in artworks
  - unless _.find(cart_items, (ci) -> ci.id == artwork.id)
    - alert 'not in the cart'
于 2012-06-05T20:19:47.303 回答