У меня есть 2 функции, где у меня есть много переменных. Я хочу также прочитать эти переменные вне функции. поэтому я могу прочитать это значение и применить, если это условие. пожалуйста помоги.Чтение значения переменной foreach вне функции
А вот функции,
var dynamicFormObject = new dynamicObject(jsonDataModel);
function dynamicObject(jsonData) {
this.formId = jsonData[0].formName;
console.log(this.formId);
this.formType = jsonData[0].formType;
this.formLayout = jsonData[0].formLayout;
this.sectionCount = jsonData[0].sections.length;
this.getSectionDetails = sectionDetails(jsonData[0].sections);
this.formRows = getSetionFieldDetails(jsonData[0].sections);
this.formFields = getContainedFields(jsonData[0].sections);
this.getNoOfSections = function(jsonData) {
return jsonData[0].sections.length;
};
}
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";
}
}
sectionDetails(jsonDataModel);
console.log(sectionDetails[0].sectionLayout);
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);
}
Когда вы показываете слишком много данных, никто не осмеливается помочь. По крайней мере, я этого не делаю. Пожалуйста, уменьшите ваши данные до минимума. –
Согласен, я отказался читать стену кода. Однако, если вы представили проблему точно, ответ ниже. – Dan
Я сократил длину кода. скажите мне, как получить эту переменную значение вне функции и значение переменной foreach, а также – user3017728