簡體   English   中英

Haml Coffee Assets模板錯誤,無法訪問Backbone JS模型?

[英]Haml Coffee Assets Template Error, no access to Backbone JS model?

我在Rails 3.2應用程序中使用haml_coffee_assets。 以下在ejs模板中有效:

<table>
  <tr>
    <th></th>
  </tr>
  <% tutorials.each(function(model) { %>
    <tr>
      <td><%= model.escape('title') %>
    </tr>
  <% }); %>
</table>

我似乎無法在haml_coffee中工作。 以下是我的最佳猜測,但由於某種原因,此haml_coffee模板不起作用:

%table
  %thead
    %tr
      %th Tutorial Name
  %tbody
    - for tutorial in @tutorials
      - do (model) ->
      %tr
        %td= model.title

我得到的是:

ReferenceError: Can't find variable: model

由於您已經提到過在GitHub問題上使用Backbone,因此我假設@tutorials是Backbone集合,並且您也可以使用以下替代方法:

%table
  %thead
    %tr
      %th Tutorial Name
  %tbody
    - for model in @tutorials.models
      %tr
        %td= model.escape('title')

我終於可以通過以下方法使它起作用:

%table
  %thead
    %tr
      %th Tutorial Name
  %tbody
    - @tutorials.each (model) ->
      %tr
        %td= model.escape('title')

希望這對別人有幫助!

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM