播放2.1-RC2:将JsValue转换为Scala值(Play 2.1-RC2: Converting JsValue to Scala Value)
我是一名初学者,尝试将我的网络应用程序从Play 2.0.4迁移到全新的Play 2.1-RC2。 由于新的JSON处理,我的代码无法编译。
我已阅读Mandubians博客 , Play 2.1迁移指南和Play JSON库文档(测试版),但我仍然不确定迁移代码的最佳方法是什么。
F.ex. 我有一个叫做
File
的模型,带有一个隐式的Read-Object(Play 2.0):object File { implicit object FileReads extends Reads[File] { def reads(json: JsValue) = File( (json \ "name").as[String], (json \ "size").as[Long] ) } }
我在控制器中使用它(Play 2.0):
val file = webserviceResult.json.as[models.File]
Play 2.1迁移指南告诉我用这样的
JsSuccess()
重构它(Play 2.1?):object File { implicit object FileFormat extends Format[File] { def reads(json: JsValue) = JsSuccess(File( (json \ "name").as[String], (json \ "size").as[Long] )) } }
但是,我现在该如何使用这种隐式转换?
或者在Play for Scala-book的Twitter示例中使用
implicit val
-stuff更好? 什么是将JsValue转换为Scala值的最佳方法?I am a play beginner and try to migrate my web application from Play 2.0.4 to the new shiny Play 2.1-RC2. My code doesn't compile because of the new JSON handling.
I have read Mandubians Blog, the Play 2.1 Migration guide and the Play JSON library documentation (beta) but I am still unsure what's the best way to migrate my code.
F.ex. I have a model called
File
with an implicit Read-Object (Play 2.0):object File { implicit object FileReads extends Reads[File] { def reads(json: JsValue) = File( (json \ "name").as[String], (json \ "size").as[Long] ) } }
I use it like this in the controller (Play 2.0):
val file = webserviceResult.json.as[models.File]
The Play 2.1 Migration guide tells me to refactor it with a
JsSuccess()
like this (Play 2.1?):object File { implicit object FileFormat extends Format[File] { def reads(json: JsValue) = JsSuccess(File( (json \ "name").as[String], (json \ "size").as[Long] )) } }
But how can I use this implicit conversion now?
Or is it better to use the
implicit val
-stuff like in the Twitter-example from the Play for Scala-book? Whats the best way to convert a JsValue to it's Scala value?
原文:https://stackoverflow.com/questions/14291666
最满意答案
$('button').on('click', function(){ answer = confirm("Are you sure?") if (answer == true) { var id = $(this).attr('id'); deleteComment(id); } else { // nothing happens } });
$('button').on('click', function(){ answer = confirm("Are you sure?") if (answer == true) { var id = $(this).attr('id'); deleteComment(id); } else { // nothing happens } });
相关问答
更多-
我不会在这里发现任何新东西。 所创建的评论会提供所有最相关的信息。 你应该看看有很好支持并且易于定制的开源替代品。 看看BootBoxJS (它取决于jQuery)。 在该站点中,您可以找到警报,对话框和其他有用工具的示例。 例如 要使用提到的软件: 下载压缩的js库 (包括js,css等) 解压文件,无论你想要什么。 然后复制并粘贴示例代码 ,并将其保存为example.html或任何您想要的内容。 现在更改链接,使其指向您下载的文件(请参阅我如何更改我的文件 ) 保存该文件并使用您的首选浏览器进行测试。 ...
-
要在确认/警报后提交,请添加一些变量作为确认状态。 var confirmed=false;//our state of alert/confirm $(document).on('submit', '#form1', function(e){ if (!confirmed) e.preventDefault();//if not confirmed submit is blocked bootbox.alert("Hello world!", ...
-
$('button').on('click', function(){ answer = confirm("Are you sure?") if (answer == true) { var id = $(this).attr('id'); deleteComment(id); } else { // nothing happens } }); $('button').on('click', function(){ ...
-
为此,您根本不需要Jquery和Jquery.UI (: - /)。 说实话,这个简单的事情可以用纯粹的javascript完成。 function showme(selEle) { alert('Selected value : '+selEle.value.toString()+'\nSelected item : '+selEle.options[selEle.selectedIndex].innerHTML); }else{ if (confirm("Confirm Order Submission ?")) return true; else return false; } 这使它工作! else{ if (confirm("Confirm Order Submission ?")) return true; else return false; } This made it work !
如何在使用jquery确认提交表单之前显示确认框?(How to display a confirm box before submitting a form using jquery confirm?)[2022-04-20]
您可以使用“标志”来确定是否发生了“阻止默认”提交行为的确认。 删除内联onsubmit = "ValidateMyform(this);" 并使用jQuery事件处理程序。 var confirmed = false; $("#ReceptionForm").on("submit", function(e){ // if confirm == true here // And if the form is valid... // the event won't be prevented a ...Modal窗口中的弹出窗口替换JS确认和警告 - ASP.NET(A popup in an Modal window to replace JS confirm and alert - ASP.NET)[2021-04-08]
你在使用任何特定的图书馆吗? 许多流行的库都内置或作为插件提供 jQuery的 dijit.dialog (道场) MochaUI (Mootools) Are you using any specific library? Many popular libraries have this built in or available as plugins jQuery dijit.dialog (Dojo) MochaUI (Mootools)如何使用Nokgiri或Mechanize确认JavaScript弹出窗口(How to confirm a JavaScript popup using Nokgiri or Mechanize)[2022-05-11]
Nokogiri和Mechanize因为它构建在Nokogiri之上,可以解析HTML并返回