2012-08-02 127 views
0

我想帮助尝试和调试我的代码返回一个对象,而不是我期望看到的。我是jquery和javascript的新手,虽然学习,我似乎无法调试此问题。当我在控制台输出输出时,我得到对象,但所有的数据都在那里。应该发生的事情是,id被传递给actionrow,并且这会将ajax调用到db。如果有人能检查代码并指出我明显的错误,我将不胜感激。 oblect从console.log(datarow)输出;在代码中。非常感谢需要JavaScript对象帮助

我使用jqxWidgets网格和数据

// action row. 
    $("#actionrowbutton").bind('click', function() { 
    var selectedrowindex = $("#jqxgrid").jqxGrid('getselectedrowindex'); 
    var datarow = $("#jqxgrid").jqxGrid('getrowdata', selectedrowindex); 
    var rowscount = $("#jqxgrid").jqxGrid('getdatainformation').rowscount; 

    if (selectedrowindex >= 0 && selectedrowindex < rowscount) { 
     var rows = $('#jqxgrid').jqxGrid('getrows', selectedrowindex); 
     var id = $("#jqxgrid").jqxGrid('getrowid', selectedrowindex); 
     //var service = datarow; 
      console.log(datarow); 

    $("#jqxgrid").jqxGrid('actionrow', id); 

    //Open action dialog window 
    $("#actionWindow").dialog({ 
    //title: 'action error', 
     resizable: false, 
     modal: true, 
     position: ['center', 'center'], 
      buttons: { 
      "Ok": function() { 
       $(this).dialog("close"); 

    $('#jqxgrid').jqxGrid('refreshdata'); 
    }, 
       Cancel: function() { 
    $(this).dialog("close"); 

    //$('#jqxgrid').jqxGrid('refreshdata'); 
    } 
    } 
}); 
    } 
}); 


actionrow: function (actrowid) { 
      // synchronize with the server - send action command 
      var data = "action=true&id=" + actrowid; 
      $.ajax({ 
     dataType: 'json', 
     url: 'data.php', 
     data: data, 
     success: function (data, status, xhr) { 
     // action command is executed. 
     } 
     });       
     } 

回答

1

我不熟悉jqxGrid组件,但是我格式化你的代码,使其更具可读性。

// action row. 
     $("#actionrowbutton").bind('click', function() { 
      var selectedrowindex = $("#jqxgrid").jqxGrid('getselectedrowindex'); 
      var datarow   = $("#jqxgrid").jqxGrid('getrowdata', selectedrowindex); 
      var rowscount  = $("#jqxgrid").jqxGrid('getdatainformation').rowscount; 

      if (selectedrowindex >= 0 && selectedrowindex < rowscount) { 
       var rows = $('#jqxgrid').jqxGrid('getrows', selectedrowindex); 
       var id = $("#jqxgrid").jqxGrid('getrowid', selectedrowindex); 
       //var service = datarow; 
       console.log(datarow); 

       $("#jqxgrid").jqxGrid('actionrow', id); 

       //Open action dialog window 
       $("#actionWindow").dialog({ 
        //title: 'action error', 
        resizable: false, 
        modal: true, 
        position: ['center', 'center'], 
        buttons: { 
         "Ok": function() { 
          $(this).dialog("close"); 
          $('#jqxgrid').jqxGrid('refreshdata'); 
         }, 
         Cancel: function() { 
          $(this).dialog("close"); 
          //$('#jqxgrid').jqxGrid('refreshdata'); 
         } 
        } 
      }); 
     } 
    }); 


    actionrow: function (actrowid) { 
     // synchronize with the server - send action command 
     var data = "action=true&id=" + actrowid; 
     $.ajax({ 
      dataType: 'json', 
      url: 'data.php', 
      data: data, 
      success: function (data, status, xhr) { 
      // action command is executed. 
      } 
     });       
    } 

再次查看后,我留下了一个问题。 什么是“actionrow”,是jqxgrid对象的函数还是方法?如果不是这样的话,应该这样写:

function actionrow(actrowid) { 
    // synchronize with the server - send action command 
    var data = "action=true&id=" + actrowid; 
    $.ajax({ 
     dataType: 'json', 
     url: 'data.php', 
     data: data, 
     success: function (data, status, xhr) { 
     // action command is executed. 
     } 
    });       
} 

并且在你的if语句中被调用。

actionrow(id); //not $("#jqxgrid").jqxGrid('actionrow', id); 
+0

达米安,对不起,我只做了一段时间的js和你的回答,虽然我确信我是正确的,让我离开我的深度。我将如何适应你的代码。谢谢 – user1532468 2012-08-02 19:50:44

+0

@ user1532468 - 不,我很抱歉,我应该更清楚地阅读你的文章,不要看到你正在使用小工具,所以我放错了。让我再看看并编辑。 – Damian 2012-08-02 20:16:41

+0

达米安。 actionrow包含调用过ajax。该行是jqxGrid参数,用于说明在这种情况下,将id传递给ajax。但是,没有什么是通过data.php。没有什么是通过萤火虫回来,也没有任何回声命令等。谢谢 – user1532468 2012-08-03 15:07:04