Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/81.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Scala.js jQuery ajax调用示例_Javascript_Jquery_Ajax_This_Scala.js - Fatal编程技术网

Javascript Scala.js jQuery ajax调用示例

Javascript Scala.js jQuery ajax调用示例,javascript,jquery,ajax,this,scala.js,Javascript,Jquery,Ajax,This,Scala.js,我尝试使用scala.js,但有些东西我不懂。我将感谢你的帮助 import org.scalajs.dom.raw.HTMLElement import org.scalajs.jquery.{jQuery => JQ, JQueryAjaxSettings, JQueryXHR} def tableEvents() = JQ("td > a").click { () => JQ.ajax(js.Dynamic.literal( `type` = "

我尝试使用scala.js,但有些东西我不懂。我将感谢你的帮助

import org.scalajs.dom.raw.HTMLElement
import org.scalajs.jquery.{jQuery => JQ, JQueryAjaxSettings, JQueryXHR}

def tableEvents() =
  JQ("td > a").click { () =>
    JQ.ajax(js.Dynamic.literal(
      `type` = "GET",
      url = "/update",
      data = "id="+({ (x: HTMLElement) => JQ(x).parent().prev().html() }: js.ThisFunction),
      // Not working. How to get "this" element here? 
      // Can I use something like Map or Seq to send of many parameters?
      dataType = "json",
      success = { (data: js.Any, textStatus: String, jqXHR: JQueryXHR) =>
        // how to convert data: js.Any to Json ?
      }
    ).asInstanceOf[JQueryAjaxSettings])
  }
我试图在这里重复已经在工作的JavaScript代码:

function tableEvents() {
  $("td > a").click(function() {
    $.ajax( {
      type: "GET",
      url: "/update",
      data: {id: $(this).parent().prev().html()},
      dataType: "json",
      success: function(data) {
        $("#id").html(data.id);
        $("#name").val(data.name);
        $("#score").val(data.score);
      }
    })
  })
}

这里需要将
参数传递给
指定的lambda。单击
。因此,您必须将该lambda转换为一个
js.ThisFunction

JQ("td > a").click({ (thiz: HTMLElement) =>
  // Now You can use thiz
}: js.ThisFunction)

我得到了json,所以:val json=json.parse(json.stringify(data))。没有更简单的办法吗?我不知道你现在在说什么/想做什么。无论如何,这可能值得一个单独的问题。如果您将data:js.Any更改为data:js.Dynamic,我相信您将不必执行JSON.parse(JSON.stringify(data)),因为它已经被声明为动态的