1

示例模板:

%input{ @attributes }

示例渲染:

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

带有haml的示例输出:

<input foo="bar">

我试图用 haml-coffe 来实现这一点,JST['example_template']({attributes: {foo: 'bar'}}但它似乎不像我预期的那样工作。

如何使用haml-coffee 完全动态地赋予所有属性?

4

1 回答 1

2

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)
于 2013-11-25T07:05:39.083 回答