0

我正在使用 Scala-Play 2.5.10、Play-Bootstrap 和 AngularJS 1.x,我需要从 AngularJS 处理一份表单提交。然后我尝试了:

@b3.submit('class -> "btn btn-danger", 
           'ng-click -> "runInSampleSimulation()") { 
                <span class="glyphicon glyphicon-cog"></span> Run Simulation 
}

ng-click无法识别。我希望它会简单地作为键值对传递到 Map 中,即<button type="@buttonType" @toHtmlArgs(innerArgsMap)>@text</button> 参见此处

所以我只能选择退回到这样的计划 HTML:

<button type="submit" class="btn btn-danger" ng-click="runInSampleSimulation()">
    <span class="glyphicon glyphicon-cog"></span> Run Simulation
</button>

有没有办法连接ng-click到b3?

4

1 回答 1

0

我决定通过更改form而不是submit按钮并使用ng-submit.

显然没有开箱即用的解决方案。虽然我所希望的是符号通过,但由于某种原因,破折号-是模板的非法符号。因此,这将给出一个错误:

@b3.form(routes.Simulation.computeInSample, 'ng-submit -> "runInSampleSimulation()") {

所以我把表单模板修改成这样的自定义b3/ngform.scala.html

@(action: Call, args: (Symbol, Any)*)(body: => Html)(implicit fc: b3.B3FieldConstructor)
<form method="@action.method" ng-submit="@bs.Args.get(args, 'ngsubmit)&#40;'@action.toString'&#41;"
      class="@fc.formClass @bs.Args.get(args, 'class)"
      @toHtmlArgs(bs.Args.remove(bs.Args.remove(bs.Args.inner(args, 'role -> "form"), 'ngsubmit), 'class).toMap)>
@body
</form>

然后我可以这样使用:

@b3.ngform(routes.Simulation.computeInSample, 'ngsubmit -> "runInSampleSimulation") {

并生成我想要的东西:

<form class="form-horizontal ng-pristine ng-valid" 
      role="form" method="GET" ng-submit="runInSampleSimulation('/simulation/in/')">
于 2017-03-21T12:15:41.870 回答