检索模板中的json值 [英] Retrieve json value in templates
本文介绍了检索模板中的json值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我从表中查询了以下对象,之后将各种对象放入以下objarr中。如何在javascript中在UI中检索这些值
I have the following objects queried form a table after which the various objects are put In the following objarr.How to retrieve these values in UI in javascript
from django.core.serializers import serialize
json = serialize("json", objarr)
logging.debug(type(json))
response_dict.update({'objarr' : (json) })
return HttpResponse(simplejson.dumps(response_dict), mimetype = 'application/javascript')
Logging.debug给出以下内容
Logging.debug gives the following
{'obj_arr': '[{"pk": 56, "model": "upload_info", "fields": {"emp_id": 13, "import_flag": 1, "resource": null, "feedback": "some feedabck", "hint": "test", "time": null, "created_by": 145, "access": 0, "keywords": "test1,test9", "type": 4, "error_flag": 0, }}, {"pk": 1156, "model": "upload_info", "fields": {"emp_id": 13, "import_flag": 1, "resource": null, "feedback": "some feedabck", "hint": "test", "time": null, "created_by": 145, "access": 0, "keywords": "test1,test9", "type": 4, "error_flag": 0, }}] }
在UI中我尝试访问emp_id的值,我该怎么做
In the UI i try to have to access the value of emp_id ,how do i do it
function retrieve_data(formid)
{
var form = $(formid);
form.ajaxSubmit({
dataType: 'json',
success: function (data) { //Data is the rendered oject of resposne_dict
if((data)
{
alert(load_flag);
How to print emp_id,error_flag and other details here
}
}
} ) ;
}
推荐答案
您需要下载 json2.js文件并将其添加到您的应用程序
You need to download the json2.js file and add it to your application
在响应中尝试这个
if((data)
{
var response=eval("("+JSON.stringify(data)+")");
for(var i=0;i<esponse.obj_arr[0].fields;i++){
var emp= response.obj_arr[0].fields[i].emp_id
}
}
您将获得的价值变量emp中的emp_id ..
You will get the value of emp_id in the variable emp..
同样适用于其他人
response.obj_arr[0].fields[i].import_flag
response.obj_arr[0].fields[i].resource
response.obj_arr[0].fields[i].feedback
并将它们分配给变量......
and assigning them in a variable...
这篇关于检索模板中的json值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文