2016-03-31 17 views
0

Bir şablonu içinde aşağıdaki işlevi ettik Nasıl:oyunda diğer eylem için parametre olarak harekete kullanmak 2.0

@activeLink(currentPath:String) = @{ 
    if(request.path.equals(currentPath)) { 
     "active" 
    } 

} 

(from: Play Framework: How do I change active class on route change)

Şimdi hoşuma demek isterseniz:

play.sbt.PlayExceptions$CompilationException: Compilation error[illegal start of simple expression] 
    at play.sbt.PlayExceptions$CompilationException$.apply(PlayExceptions.scala:27) ~[na:na] 
    at play.sbt.PlayExceptions$CompilationException$.apply(PlayExceptions.scala:27) ~[na:na] 
    at scala.Option.map(Option.scala:145) ~[scala-library-2.10.5.jar:na] 
    at play.sbt.run.PlayReload$$anonfun$taskFailureHandler$1.apply(PlayReload.scala:49) ~[na:na] 
    at play.sbt.run.PlayReload$$anonfun$taskFailureHandler$1.apply(PlayReload.scala:44) ~[na:na] 
    at scala.Option.map(Option.scala:145) ~[scala-library-2.10.5.jar:na] 
    at play.sbt.run.PlayReload$.taskFailureHandler(PlayReload.scala:44) ~[na:na] 
    at play.sbt.run.PlayReload$.compileFailure(PlayReload.scala:40) ~[na:na] 
    at play.sbt.run.PlayReload$$anonfun$compile$1.apply(PlayReload.scala:17) ~[na:na] 
    at play.sbt.run.PlayReload$$anonfun$compile$1.apply(PlayReload.scala:17) ~[na:na] 
    at scala.util.Either$LeftProjection.map(Either.scala:377) ~[scala-library-2.10.5.jar:na] 
    at play.sbt.run.PlayReload$.compile(PlayReload.scala:17) ~[na:na] 
    at play.sbt.run.PlayRun$$anonfun$playRunTask$1$$anonfun$apply$2$$anonfun$apply$3$$anonfun$2.apply(PlayRun.scala:61) ~[na:na] 
    at play.sbt.run.PlayRun$$anonfun$playRunTask$1$$anonfun$apply$2$$anonfun$apply$3$$anonfun$2.apply(PlayRun.scala:61) ~[na:na] 
    at play.runsupport.Reloader$$anonfun$reload$1.apply(Reloader.scala:323) ~[na:na] 
    at play.runsupport.Reloader$$anon$3.run(Reloader.scala:43) ~[na:na] 
    at java.security.AccessController.doPrivileged(Native Method) ~[na:1.8.0_60] 
    at play.runsupport.Reloader$.play$runsupport$Reloader$$withReloaderContextClassLoader(Reloader.scala:39) ~[na:na] 
    at play.runsupport.Reloader.reload(Reloader.scala:321) ~[na:na] 
    at play.core.server.DevServerStart$$anonfun$mainDev$1$$anon$1$$anonfun$get$1.apply(DevServerStart.scala:113) ~[play-server_2.10-2.4.6.jar:2.4.6] 
    at play.core.server.DevServerStart$$anonfun$mainDev$1$$anon$1$$anonfun$get$1.apply(DevServerStart.scala:111) ~[play-server_2.10-2.4.6.jar:2.4.6] 
    at scala.concurrent.impl.Future$PromiseCompletingRunnable.liftedTree1$1(Future.scala:24) ~[scala-library-2.10.5.jar:na] 
    at scala.concurrent.impl.Future$PromiseCompletingRunnable.run(Future.scala:24) ~[scala-library-2.10.5.jar:na] 
    at akka.dispatch.TaskInvocation.run(AbstractDispatcher.scala:40) ~[akka-actor_2.10-2.3.13.jar:na] 
    at akka.dispatch.ForkJoinExecutorConfigurator$AkkaForkJoinTask.exec(AbstractDispatcher.scala:397) ~[akka-actor_2.10-2.3.13.jar:na] 
    at scala.concurrent.forkjoin.ForkJoinTask.doExec(ForkJoinTask.java:260) ~[scala-library-2.10.5.jar:na] 
    at scala.concurrent.forkjoin.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1339) ~[scala-library-2.10.5.jar:na] 
    at scala.concurrent.forkjoin.ForkJoinPool.runWorker(ForkJoinPool.java:1979) ~[scala-library-2.10.5.jar:na] 
    at scala.concurrent.forkjoin.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:107) ~[scala-library-2.10.5.jar:na] 
:
@activeLink(@routes.Application.index().url) 

Ama aşağıdaki hatayı alıyorum

URL'yi şablon içindeki bir işleve iletmenin doğru yolu nedir?

Oynat 2.4.6 ile test edilmiştir ve Java 8.

cevap

1

Parametre olmadan geçmesi gerekir '@'

+0

@activeLink(routes.Application.index().url) Sağolun efendim deneyin. Bunun nerede belgelendiğini biliyor musun? Neden böyle? – visil

+0

Rica ederim, '@' karakteri, scala kodunun yorumlanmasının başlangıcını tanımlar. https://www.playframework.com/documentation/2.5.x/ScalaTemplates bölüm "Sözdizimi: büyü‘ @ "karakteri" – OBuiron