如何在jQuery的,JTable的插件加载JSON数据? [英] How to load JSON Data in jQuery-jTable plugin?

查看:964
本文介绍了如何在jQuery的,JTable的插件加载JSON数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建使用表格形式 JTable中插件。它主要侧重于ASP或PHP MVC的,但我想用JavaScript / html和蒙戈后端实现它。

I am working on creating a table form using jTable plugin. It mainly focus for ASP or PHP MVC but I'm trying to implement it with javascript/html and mongo backend.

我经历了整个 JTable的API文档,我发现有填充JSON API架构向表的可能性,相当similiar在flexigrid。

I went through entire jTable API documentation and I found out there is possibility of populating json schema api into table, quite similiar in flexigrid.

在code是这样的:

 $(document).ready(function () {
          $('#feeds-table').jtable({
              title: 'Accounts',
              pageSize: 15,
              ajaxSettings: {
                  type: 'GET',
                  dataType: 'json'
              },
              actions: {

              },
              fields: {
                  id: {
                      key: true,
                      list: false
                  },
                  username: {
                      title: 'Username',
                      width: '10%'
                  },
                  email: {
                      title: 'Email',
                      width: '10%'
                  },
                  applications: {
                      title: 'Applications',
                      width: '10%'
                  },
                  sites: {
                      title: 'Sites',
                      width: '10%'
                  },
                  verticals: {
                      title: 'Verticals',
                      width: '10%'
                  },
                  roles: {
                      title: 'Roles',
                      width: '10%'
                  },
                  profiles: {
                      title: 'Record date',
                      width: '30%',
                      type: 'date',
                      create: false,
                      edit: false
                  }
              }
          });
      });

如果有人能帮助我找出我应该使用URL属性还是有在API参考任何其他方法来获取数据,并在表中显示。请让我知道!

If anyone can help me to find out where should I use URL property or is there any other method in the API reference to GET the data and display in table. Please let me know!

推荐答案

您可以通过'listAction设置为一个JSON文件直接加载JSON数据。

You can directly load JSON data by setting the 'listAction' to a JSON document .

例如:

actions: {
  listAction: 'url/file.json',
},

您JSON文件需要有指定相同的字段和下一个结构:

Your JSON file needs to have the same fields specified and the next structure:

{
 "Result":"OK",
   "Records":[
    {"PersonId":1,"Name":"Benjamin Button","Age":17,"RecordDate":"\/Date(1320259705710)\/"},
    {"PersonId":2,"Name":"Douglas Adams","Age":42,"RecordDate":"\/Date(1320259705710)\/"},
    {"PersonId":3,"Name":"Isaac Asimov","Age":26,"RecordDate":"\/Date(1320259705710)\/"},
    {"PersonId":4,"Name":"Thomas More","Age":65,"RecordDate":"\/Date(1320259705710)\/"}
   ]
}

的常用方法是指向的'listAction'到服务器侧脚本(PHP,ASP.NET ...)返回上述JSON对象

The common way is to point the 'listAction' to a server side script (PHP,ASP.NET...) that return the above JSON object.

检查以了解更多信息 listAction API参考: ApiReference-listAction

Check the listAction API reference for more information: ApiReference-listAction

这篇关于如何在jQuery的,JTable的插件加载JSON数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆