简体   繁体   English

在没有ajax请求的情况下将数据添加到jQuery-Flexigrid

[英]Adding data to jQuery-Flexigrid without ajax-request

I want to save some unneeded requests and time for displaying a table the first time and so I thought maybe I could set the initial data directly without any ajax-request. 我想节省一些不需要的请求和第一次显示表的时间,所以我想也许我可以直接设置初始数据而无需任何ajax请求。 I tried it like that: 我这样尝试过:

$('#testTable').flexAddData('[formatted json here]');

and also that 还有那个

$('#testTable').addData('[formatted json here]');

But it hasn't any effect. 但这没有任何作用。 Can I do that and what is the right syntax? 我可以这样做,正确的语法是什么?

I've also met this problem and spent a lot of time trying to solve it. 我也遇到了这个问题,并花了很多时间来解决它。 Solution in my case was pretty simple. 就我而言,解决方案非常简单。 You just need to specify dataType : "json" obviously in flexigrid() function. 您只需要在flexigrid()函数中指定dataType:“ json” flexigrid() Default dataType is XML. 默认dataType为XML。 So, it don't want to understand JSON: 因此,它不想了解JSON:

$("#myTable").flexigrid({dataType : "json"});

Did you use the eval() ? 您是否使用过eval()

$("#testTable").flexAddData(eval('[formatted json here]'));

or try 或尝试

$("#testTable").flexAddData(eval('[formatted json here]')).flexReload();

hope this helps 希望这可以帮助

To supplement Anwar and user1635430 answers, here is an example JSON code: 为了补充Anwaruser1635430的答案,下面是一个示例JSON代码:

{
"page": "1",
"total": "9",
"rows": [
    {
        "id": "1",
        "cell": [
            "1",
            "text1",
            "user1",
            "date1"
        ]
    }
 ]
}

The code is done by Anwar , I "stole" it from his answer on some other question. 该代码由Anwar完成,我从他对其他问题的回答中“偷走”了它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM