json数据字典,以及数据在下拉框中显示
建立person_vocation.json数据字典文件,内容:
[ {"id":1,"disabled":false,"selected":false,"name":"政府部门"}, {"id":2,"disabled":false,"selected":false,"name":"教科文"}, {"id":3,"disabled":false,"selected":false,"name":"金融"}, {"id":4,"disabled":false,"selected":false,"name":"商贸"}, {"id":5,"disabled":false,"selected":false,"name":"房地产"}, {"id":6,"disabled":false,"selected":false,"name":"制造业"}, {"id":7,"disabled":false,"selected":false,"name":"自由职业"}, {"id":9,"disabled":false,"selected":false,"name":"事业单位"}, {"id":10,"disabled":false,"selected":false,"name":"国有企业"}, {"id":11,"disabled":false,"selected":false,"name":"公务员"}, {"id":12,"disabled":false,"selected":false,"name":"专业技术人员"}, {"id":13,"disabled":false,"selected":false,"name":"办事人员"}, {"id":14,"disabled":false,"selected":false,"name":"军人"}, {"id":15,"disabled":false,"selected":false,"name":"商业和服务类人员"}, {"id":16,"disabled":false,"selected":false,"name":"生产、运输设备操作人员"}, {"id":18,"disabled":false,"selected":false,"name":"农、林、牧、渔、水利业生产人员"}, {"id":98,"disabled":false,"selected":false,"name":"其它"} ]
下拉框显示数据字典中的数据:
//职业下拉框 $.getJSON("../TextData/person_vocation.json",function(vocationData){ $('.dropdown-dutyType').dropdown({ data: vocationData, input: '<input type="text" maxLength="20" placeholder="请输入搜索">', choice: function() { // console.log(arguments, this); } }); });
有时候$.getJSON加载数据字典异步会出现问题:
同时执行多个$.getJSON() 数据混乱的问题的解决
在执行之前加$.ajaxSettings.async = false; (同步执行) 执行你的代码之后及时恢复为$.ajaxSettings.async = true; (异步执行) 不然影响别的地方的需要异步执行的代码。
example:
$.ajaxSettings.async = false;
$.getJSON(url, data, function(data){ });
$.getJSON(url, data, function(data){ });
$.getJSON(url, data, function(data){ });
......
$.ajaxSettings.async = true;