starry_sky_wst 2015-08-19 07:35 采纳率: 50%
浏览 2737

使用jQuery获取json(使用jQWidgets控件)

使用jQWidgets控件获取json数据和解析

下面是我的一段代码

 $(document).ready(function () {
        // prepare the data
        url="http://localhost:8080/web_test/api/user";
        $.ajax({
            dataType: json,
            url: url,
            data: "",
            success: function (data, status, xhr){
                 var data = data.data;
                 var source =
                 {
                     localdata: data,
                     datatype: "json",
                     datafields:
                     [
                         { name: 'id', type: 'string' },
                         { name: 'name', type: 'string' },
                         { name: 'loginName', type: 'string' },
                         { name: 'password', type: 'string' },
                         { name: 'mobile1', type: 'number' },
                         { name: 'mobile2', type: 'number' },
                         { name: 'telephone', type: 'number' },
                         { name: 'email', type: 'string' },
                         { name: 'gender', type: 'string' },
                         { name: 'address', type: 'string' },
                         { name: 'removed', type: 'number' }
                     ]                     
                 };
            }
        });
                }

success里面,var data = data.data 能取到data里面的数据吗

下面是本地的json数据格式,我只需要取data里面的数组就行了

 {
  "info" : {
    "success" : true,
    "code" : null,
    "error" : null
  },
  "data" : [ {
    "id" : 1,
    "name" : "测试用户",
    "loginName" : "test",
    "password" : "test",
    "mobile1" : null,
    "mobile2" : null,
    "telephone" : null,
    "email" : null,
    "gender" : null,
    "address" : null,
    "removed" : 0
  }, {
    "id" : 88,
    "name" : "人生大赢家团队",
    "loginName" : "lbm",
    "password" : "lbm",
    "mobile1" : 111,
    "mobile2" : 111,
    "telephone" : "111",
    "email" : "111",
    "gender" : null,
    "address" : null,
    "removed" : 0
  }, {
    "id" : 21,
    "name" : "研发团队测试",
    "loginName" : "testTWW",
    "password" : "testTWW",
    "mobile1" : null,
    "mobile2" : null,
    "telephone" : null,
    "email" : null,
    "gender" : null,
    "address" : null,
    "removed" : 0
  } ]
}

这些方法是jQWidgets使用的,但是我得不到结果,应该会显示一张表格,求大神帮忙看看,万分感谢

  • 写回答

4条回答 默认 最新

  • 残缺丶 2015-08-19 08:23
    关注

    $("#jqxgrid").jqxGrid(
    {
    width: 850,
    source: dataAdapter,

    pageable: true,
    autoheight: true,
    sortable: true,
    altrows: true,
    enabletooltips: true,
    editable: true,
    selectionmode: 'multiplecellsadvanced',
    columns: [
    { text: 'Product Name', columngroup: 'ProductDetails', datafield: 'ProductName', width: 250 },
    { text: 'Quantity per Unit', columngroup: 'ProductDetails', datafield: 'QuantityPerUnit', cellsalign: 'right', align: 'right', width: 200 },
    { text: 'Unit Price', columngroup: 'ProductDetails', datafield: 'UnitPrice', align: 'right', cellsalign: 'right', cellsformat: 'c2', width: 200 },
    { text: 'Units In Stock', datafield: 'UnitsInStock', cellsalign: 'right', cellsrenderer: cellsrenderer, width: 100 },
    { text: 'Discontinued', columntype: 'checkbox', datafield: 'Discontinued' }
    ],
    columngroups: [
    { text: 'Product Details', align: 'center', name: 'ProductDetails' }
    ]
    });

                        将你的json数据绑定就可以了啊
    
    评论

报告相同问题?

悬赏问题

  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3
  • ¥15 用matlab 设计一个不动点迭代法求解非线性方程组的代码
  • ¥15 牛顿斯科特系数表表示
  • ¥15 arduino 步进电机
  • ¥20 程序进入HardFault_Handler
  • ¥15 oracle集群安装出bug
  • ¥15 关于#python#的问题:自动化测试