jquery tmpl 的 json
我可以在 jquery 模板中使用这种格式的 JSON 吗?
{
"ROWCOUNT": 3,
"COLUMNS": [
"UTCODICE",
"UT__NOME",
"UT__COGN"
],
"DATA": {
"UTCODICE": [
1088,
1087,
1086
],
"UT__NOME": [
'Roberto',
'Paolo',
'Carlo'
],
"UT__COGN": [
'Gino',
'Luigi',
'Luca'
]
}
}
...或者...
{
"COLUMNS": [
"UTCODICE",
"UT__NOME",
"UT__COGN"
],
"DATA": [
[
1088,
'Roberto',
'Gino'
],
[
1087,
'Paolo',
'Luigi'
],
[
1086,
'Carlo',
'Luca'
]
]
}
我该如何让jquery从“DATA”标签开始解析?
非常感谢!
can i use this format JSON with jquery template?
{
"ROWCOUNT": 3,
"COLUMNS": [
"UTCODICE",
"UT__NOME",
"UT__COGN"
],
"DATA": {
"UTCODICE": [
1088,
1087,
1086
],
"UT__NOME": [
'Roberto',
'Paolo',
'Carlo'
],
"UT__COGN": [
'Gino',
'Luigi',
'Luca'
]
}
}
... or...
{
"COLUMNS": [
"UTCODICE",
"UT__NOME",
"UT__COGN"
],
"DATA": [
[
1088,
'Roberto',
'Gino'
],
[
1087,
'Paolo',
'Luigi'
],
[
1086,
'Carlo',
'Luca'
]
]
}
how can i say to jquery to start parsing from "DATA" tag?
many thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
第二个看起来应该可行,但您需要将所有单引号 (
'
) 更改为双引号 ("
)。没有办法告诉 jQuery 从哪里开始解析,它一次性完成整个事情,但是,一旦解析完毕,您应该能够执行以下操作:
访问对象的 DATA 部分。
The second one looks like it should work, but you'll want to change all of the single quotes (
'
) to double-quotes ("
).There's no way to tell jQuery where to start parsing, it does the whole thing in one shot. However, once it's parsed, you should be able to just do:
to access the DATA part of the object.
您需要一份 JSON2.js
https://github.com/douglascrockford/JSON-js
然后你可以这样做:
其中 data 是上面的字符串
这里有一个很好的例子:
http://weblogs.asp.net/dwahlin/archive/2010/11/20/reducing-code-by-using-jquery-templates.aspx< /a>
例如:
然后在脚本中使用 JQuery 模板解析数据
You'll need a copy of JSON2.js
https://github.com/douglascrockford/JSON-js
You can then do this:
Where data is the above string
There is a good example here:
http://weblogs.asp.net/dwahlin/archive/2010/11/20/reducing-code-by-using-jquery-templates.aspx
e.g essentially:
and then in your script parse the data using JQuery template
使用第二个 JSON 对象尝试此操作:
上面的模板为“DATA”中的每个数组创建一个表行 (tr),然后为每个数组中的每个值创建一个表单元格 (td)。
希望有帮助。
Try this with the second JSON object:
The template above creates a table row (tr) for each array in "DATA", then creates a table cell (td) for each value in each array.
Hope that helps.