Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/439.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/75.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 已将jQuery变量值发送到Scala播放路由函数_Javascript_Jquery_Scala_Playframework 2.0 - Fatal编程技术网

Javascript 已将jQuery变量值发送到Scala播放路由函数

Javascript 已将jQuery变量值发送到Scala播放路由函数,javascript,jquery,scala,playframework-2.0,Javascript,Jquery,Scala,Playframework 2.0,我有一些路线和功能看起来像: GET/item state/:id controllers.Application.getState(id:String) 我使用jQuery数据表,需要处理行单击。我尝试这样做: $('#statTable tbody').on( 'click', 'tr', function () { $(this).toggleClass('selected'); var data = table.row(this).data(); console.lo

我有一些路线和功能看起来像:

GET/item state/:id controllers.Application.getState(id:String)

我使用jQuery数据表,需要处理行单击。我尝试这样做:

$('#statTable tbody').on( 'click', 'tr', function () {
    $(this).toggleClass('selected');
   var data = table.row(this).data();
   console.log(data);
   @routes.Application.getState($(data"id"));
} );
});

但这种方式是错误的。如何在scala函数中使用jQuery var value?

我不能确切地说出您的目的,因此这里有几个选项:

普通jQuery无播放功能 Play的javascript路由器 Play有两种生成javascript路由器的方法:

  • 使用*@javascriptRouter*指令嵌入Scala模板
  • 在您的页面可以使用它们的操作中
  • 有用链接:


    好吧,在AJAX GET调用的帮助下,您可以很容易地做到这一点。每当用户选择行时,它都会生成一个ajaxget请求,该请求将路由到控制器函数

    var callurl = "/item-state/{id}";
    
    $('#statTable tbody').on( 'click', 'tr', function () {
       $(this).toggleClass('selected');
       var data-id = $(document).find('.selected').attr("data-id");
       //now by getting the id of the selected row,pass it to the url.
       callurl = callurl.replace("{id}",data-id);
       $.ajax({
         url:callurl,
         type:GET,
         success:function(data){ //if any data returned from the API,usually a JSON
             do-something;
           }
          error:function(xhr){  //display the error if resource not found or server error on the request
            notify-with-message;
          }
        )};
    
    });
    
    通过这种方式,您可以将jquery或任何脚本变量传递给路由函数。


    我的公司正在使用play框架来处理产品的webapp,我们已经做了很长时间了。因此,这是一个有效的解决方案。此外,请明确说明您的需求。如有任何疑问,请随时提问。

    进一步研究后,您可以使用更多的代码来完成与原始问题类似的操作。我不在电脑旁,所以稍后会更新。这个链接应该有助于你没有看到任何活动-你需要任何进一步的信息吗?
    var callurl = "/item-state/{id}";
    
    $('#statTable tbody').on( 'click', 'tr', function () {
       $(this).toggleClass('selected');
       var data-id = $(document).find('.selected').attr("data-id");
       //now by getting the id of the selected row,pass it to the url.
       callurl = callurl.replace("{id}",data-id);
       $.ajax({
         url:callurl,
         type:GET,
         success:function(data){ //if any data returned from the API,usually a JSON
             do-something;
           }
          error:function(xhr){  //display the error if resource not found or server error on the request
            notify-with-message;
          }
        )};
    
    });