簡體   English   中英

使用haml-coffee動態分配所有屬性

[英]Dynamically give all attributes using haml-coffee

示例模板:

%input{ @attributes }

渲染示例:

@attributes = {:foo => :bar}
render :example_template 

使用haml的示例輸出:

<input foo="bar">

我嘗試使用帶有JST['example_template']({attributes: {foo: 'bar'}} haml-coffe來實現這一點,但是它似乎並沒有達到我的預期。

如何使用haml-coffee完全動態地賦予所有屬性?

通過指定Haml-Coffee不支持的對象來指定所有屬性,您需要顯式定義在編譯時已知的所有屬性:

%input{ foo: @attributes['bar'] }

並使用

JST['example_template'](attributes: { foo: 'bar' })

如果您需要自由定義所有屬性,那么建議您在視圖中進行設置,例如

class ExampleView extends Marionette.View

  ui:
    foo: 'input[foo]'

  onRender: ->
    @ui.foo.attr(@attributes)

暫無
暫無

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

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