我从服务器发送了以下json,并且我一直试图用jsrender对其进行迭代,但未成功

{
"1": {
    "username": "one",
    "sent_email": false,
    "group": "blogger",
    "date_activated": null,
    "activated_email": false,
    "email": "email",
    "date_registered": null,
    "key": "key",
    "password": "password",
    "id": 1
},
"2": {
    "username": "Madawar",
    "sent_email": true,
    "group": "admin",
    "date_activated": "2012-07-17T00:00:00",
    "activated_email": true,
    "email": "[email protected]",
    "date_registered": "2012-08-22T11:21:39",
    "key": "e4hVRItub_A=",
    "password": "$2a$12$F3aBLpF.MyyiVDAocPzE9uJn0K5DZ1V4qRim54wl8f3tEv.7VC4ji",
    "id": 2
},
"3": {
    "username": "one",
    "sent_email": false,
    "group": "blogger",
    "date_activated": null,
    "activated_email": false,
    "email": "email",
    "date_registered": null,
    "key": "key",
    "password": "password",
    "id": 3
},
"4": {
    "username": "one",
    "sent_email": false,
    "group": "blogger",
    "date_activated": null,
    "activated_email": false,
    "email": "email",
    "date_registered": null,
    "key": "key",
    "password": "password",
    "id": 4
},
"5": {
    "username": "one",
    "sent_email": false,
    "group": "blogger",
    "date_activated": null,
    "activated_email": false,
    "email": "email",
    "date_registered": null,
    "key": "key",
    "password": "password",
    "id": 5
},
"6": {
    "username": "one",
    "sent_email": false,
    "group": "blogger",
    "date_activated": null,
    "activated_email": false,
    "email": "email",
    "date_registered": null,
    "key": "key",
    "password": "password",
    "id": 6
},
"7": {
    "username": "one",
    "sent_email": false,
    "group": "blogger",
    "date_activated": null,
    "activated_email": false,
    "email": "email",
    "date_registered": null,
    "key": "key",
    "password": "password",
    "id": 7
},
"10": {
    "username": "Madawar12",
    "sent_email": true,
    "group": "blogger",
    "date_activated": null,
    "activated_email": false,
    "email": "[email protected]",
    "date_registered": "2012-08-30T17:13:07",
    "key": "JehBfVpoheE=",
    "password": "$2a$12$V04xpEqCWSLIWl0rte2U7OQC5/TqFcDehKJiuiqRALiW3uEYTBFsK",
    "id": 10
},
"11": {
    "username": null,
    "sent_email": true,
    "group": "blogger",
    "date_activated": null,
    "activated_email": false,
    "email": null,
    "date_registered": "2012-08-30T17:16:32",
    "key": "MG7kgSUzNK0=",
    "password": "$2a$12$6gJa1L0MZn9HB/fZNk1cXe1RDjAIOaAv1ASTgBJu.OrhOMpNfCkOG",
    "id": 11
},
"12": {
    "username": null,
    "sent_email": true,
    "group": "blogger",
    "date_activated": null,
    "activated_email": false,
    "email": null,
    "date_registered": "2012-08-30T17:17:30",
    "key": "qJisSUS8osQ=",
    "password": "$2a$12$tfDdBODJFTz/afhAvm7EjOpH.Zp.Q8Jw.h312uFZCwJQTlKRI0k6G",
    "id": 12
}


}

数字1-12代表记录号,不一定是连续的,是否可以用jsrender显示此记录,还是我必须从服务器更改结果?

最佳答案

为了给您一些想法,请看一下sample,它显示了JsRender中用于遍历字段的几种方法。您可以将这些方法应用于您的方案。 (实时演示为here)。

更新:当前文档在这里:http://www.jsviews.com/#propstag

至于迭代到任何深度,您确实可以在递归使用的模板或标签中使用{{props}}-这样遍历数组和对象的层次结构到任何深度。

有一个{{jsonview/}}标记coded here就是这样做的,例如用在this jsfiddle sample中...

在这种情况下,它是否使用数据链接,所以当您以任何方式在“树”中更改数据时,jsonview输出将增量更新。相同的{{jsonview}}仅可用于JsRender。 (在这种情况下,您可以根据需要将数据链接的{^{...}}标记更改为{{...}}。)

09-26 02:21