[英]How to load JSON Data in jQuery-jTable plugin?
I am working on creating a table form using jTable plugin. 我正在使用jTable插件创建表格表单。 It mainly focus for ASP or PHP MVC but I'm trying to implement it with javascript/html and mongo backend.
它主要针对ASP或PHP MVC,但我正在尝试使用javascript / html和mongo后端来实现它。
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. 我遍历了整个jTable API文档 ,发现有可能将json模式api填充到表中,这在flexigrid中非常相似。
The code looks like: 代码如下:
$(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
}
}
});
});
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. 如果有人可以帮助我找出我应该在哪里使用URL属性,或者API参考中是否有任何其他方法来获取数据并显示在表格中。 Please let me know!
请告诉我!
You can directly load JSON data by setting the 'listAction' to a JSON document . 您可以通过将'listAction'设置为JSON文档来直接加载JSON数据。
Example: 例:
actions: {
listAction: 'url/file.json',
},
Your JSON file needs to have the same fields specified and the next structure: 您的JSON文件需要指定相同的字段和下一个结构:
{
"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)\/"}
]
}
The common way is to point the 'listAction' to a server side script (PHP,ASP.NET...) that return the above JSON object. 常见的方法是将“ listAction”指向返回上述JSON对象的服务器端脚本(PHP,ASP.NET ...)。
Check the listAction
API reference for more information: ApiReference-listAction 检查
listAction
API参考以获取更多信息: ApiReference-listAction
Use the addRecord
action. 使用
addRecord
操作。 It gives you the option to specify clientOnly: true
which will prevent jtable from making a server call when you edit a row. 它为您提供了指定
clientOnly: true
的选项,这将防止jtable在编辑行时进行服务器调用。 More Information - jtable.org-addRecord 更多信息-jtable.org-addRecord
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.