1

我在 play framework 中定义了一个自定义的 Bootstrap 字段构造函数

@(elements: helper.FieldElements)

<div class="control-group@if(elements.hasErrors) { error}">
    <label class="control-label" for="@elements.id">CIAO@elements.label(elements.lang)</label>

    <div class="controls">
        @elements.input

        @elements.errors(elements.lang).map { error =>
            <span class="help-inline">@error</span>
        }
    </div>
</div>

它按预期工作,除非我将字段放在重用视图块中:@(editForm: Form[Azienda]) @import helper._ @import crudder.viewhelpers.html.bootstrap.f @implicitField = @{ FieldConstructor(crudder. viewhelpers.html.bootstrap.f) }

@editFields() = {
    @inputText(editForm("descrizione"), '_label -> "Ragione sociale")
}

@main("Amministrazione - Aziende") {
         <!--This one use my customized block-->  
         @inputText(editForm("descrizione"), '_label -> "Ragione sociale")
         <!--This one don't work!-->  
         @editFields()

}

关于如何使可重用块使用我的自定义构造函数的任何想法?

4

1 回答 1

2

好的,看来这个问题不是那么吸引人,但是我发布了一个我发现的解决方法,以防万一它对其他人有用。

似乎隐式构造函数在块内不可见,因此我将构造函数显式传递给 inputText:

@(aziende: List[crudder.models.Persistent], editForm: Form[Azienda],id:Long)

@import helper._
@import crudder.viewhelpers.html.bootstrap.f
@Field = @{ FieldConstructor(crudder.viewhelpers.html.bootstrap.f) }

@editFields() = {

    @inputText(editForm("descrizione"), '_label -> "Ragione sociale")(Field,null)
}

@main("Amministrazione - Aziende") {
<!--This one use my customized block-->
@inputText(editForm("descrizione"), '_label -> "Ragione sociale")
<!--Now this work too!-->
@editFields()

}
于 2012-07-09T11:10:43.067 回答