我正在映射一个对象,并从对象中附加元素,而我映射元素时,我正在检查对象值并适当地附加元素。我相信在我的函数中一切都是正确的,但最后一个“if”条件只附加元素,其余条件不附加任何东西......对此有什么解决方法?
var processModules = function (mData) {
$.map(mData, function (val,i) {
$(val.container).append(
$(val.type === 'content' || val.type === 'navigation' ?
$('<div />',{
'class':val.attributes['class'],
id:val.attributes.id})
.append(val.title ? $('<h2 />',{text:val.title}) : "")
.append(val.subtitle ? $('<h3>',{text:val.subtitle}) : "")
:
val.type === 'form' ? $('<form />',{
id:val.attributes.id,
'class':val.attributes['class'],
action:val.action,
name:val.name
})
.append($('<legend />',{text:val.title}))
.append(
$.map(val.fields, function (val,i) {
var element;
if (val.label) {
element = $('<label />',{text:val.label}); // it is not appending
}
if (val.type) {
element = $('<input />',{id:val.id}) // only this is appending, if i place anything after this, only the last condition appends.. any what is the issue? pls check my json tree in the jsfiddle.
}
return element;
} )
)
: ""));
} )
}
提前致谢。