我正在使用 $.map 方法从 Json 获取数据。并且根据数据的类型,我正在制作元素并将数据说明的内容附加到容器中。它适用于所有浏览器,包括 ie9。但少于即 9,我什么也没得到。
我怎样才能解决这个问题?
我的代码:
var processModules = function (mData) {
var lMData = mData;
$.map(lMData, function (mVal,i) {
$(mVal.type === 'form' ? '<form></form>' : '<div></div>',{
id : mVal.attributes.id,
'class' : mVal.attributes['class']
})
.appendTo(mVal.container); // not appending in less than ie9.
} )
}
$(document).ready(function () {
$.getJSON('json.txt', function (data) {
if($(data['modules'])){
processModules($(data['modules']));
}
})
});
我的 json :
"modules":[
{
"type":"navigation",
"container":"#header",
"title":"Top Navigation",
"attributes":{
"class":"topNavigation",
"id":"topNavigation"
}
},
{
"type":"content",
"title":"Hi Welcome to mobile development",
"subtitle":"Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.",
"container":"#maincontent",
"attributes":{
"class":"topContent"
}
},
{
"type":"form",
"title":"Registration Form",
"action":"submit.aspx",
"name":"registrationform",
"container":"#maincontent",
"attributes":{
"class":"registrationform"
},
"fields":[
{
"id":"firstname",
"label":"First Name",
"name":"fname",
"type":"text",
"value":""
},
{
"id":"email",
"label":"Email",
"name":"email",
"type":"text",
"value":""
},
{
"id":"countries",
"label":"Country",
"name":"countries",
"type":"select",
"options":[
{
"value":"",
"text":"Select Country"
},
{
"value":"in",
"text":"India",
"selected":"true"
},
{
"value":"us",
"text":"United Stated"
},
{
"value":"uk",
"text":"United Kingdom"
},
{
"value":"cn",
"text":"Canada"
}
]
},
{
"id":"submit",
"name":"submit",
"type":"submit",
"value":"Submit"
}
]