我有一个功能,我必须访问属性。函数在foreach循环中,它看起来像这样
function sectionDetails(sectionData){
var sectionDetails = [];
if (sectionData.length > 0) {
sectionData.forEach(function(item) {
sectionDetails.push({
sectionId:item.sectionId,
sectionName:item.sectionName,
sectionLayout:item.sectionLayout
});
});
return sectionDetails;
} else {
return "Error";
}
}
我正在获取条件检查的属性值,
if ($scope.entity[0].sections[0].sectionId === 1 &&
$scope.entity[0].sections[0].sectionLayout == "linear_layout_vertical") {
if (dynamicFormObject.formLayout == "linear_layout_horizontal") {
console.log("sadasd");
var newdiv = document.createElement("div");
console.log(newdiv);
newdiv.setAttribute('horizontal', '');
newdiv.setAttribute('layout', '');
newdiv.className('col-md-12');
document.body.appendChild(newdiv);
}
else if (fieldLayout == "linear_layout_horizontal" && fieldControl === 2) {
for(var i=1; i<=2; i++) {
var newdiv = document.createElement("div");
newdiv.setAttribute('horizontal', '');
newdiv.setAttribute('layout', '');
newdiv.className('col-md-6');
document.body.appendChild(newdiv);
}
}
我需要获取通过foreach迭代的属性值并在if语句中进行比较..请帮助