【发布时间】:2018-04-05 10:11:24
【问题描述】:
我有一个路由 js,我在其中定义了这样的 get 函数:
exports.get = function (req, res) {
var calls = [{
propertyTypes: function (acc) {
return '/catalog/propertyTypes/';
},
}];
commercial_residential = {
1 : 'Residencial',
2 : 'Comercial'
}
property_types = [
[
[4 , "departamento"],
[5 , "campo"],
[8 , "casa"],
[13 , "duplex"],
[43 , "casa"],
[47 , "departamento"],
[49 , "campo"],
[50 , "Terreno"],
[53 , "departamento"],
[63 , "ph"]
],[
[1 , "Local"],
[2 , "Quinta"],
[3 , "Cochera"],
[4 , "Galpon"],
[5 , "emprendimiento"],
[6 , "Lote"],
[7 , "Oficina"],
[9 , "Fondo de Comercio"],
[10 , "Galpon"],
[12 , "fondo de comercio"],
[13 , "fondo de comercio"],
[79 , "fondo de comercio"]
]
]
fetcher.getWithDependencies(calls, function (err, results) {
var propertyTypes = (results.propertyTypes) ? results.propertyTypes : [];
[];
fetcher.get('/ilist/importer/get/property/' + id, function (e, results) {
res.render('ilist-importer/property', {
'data': results,
'list': {
'propertyQR': propertyTypes,
'propertyTypes': property_types,
}
});
});
})
};
在我的 get 函数表单中,在 ejs 文件中,我有一个组合,其中显示所有 property_types 名称。提交表单时,我需要将所选值 property_type 名称与来自 route.js 的键值数组 propertyQR 进行比较。
这是我的表单选择:
<select name="comercial" id="comercial_form" class="span3">
<option value="0">-Seleccione-</option>
<% for(var i=0; i < list.propertyTypes[1].length; i++) { %>
<option value="<%= list.propertyTypes[1][i][1] %>">
<%= list.propertyTypes[1][i][1] %>
</option>
<% } %>
</select>
这是我目前所拥有的。首先,我尝试将从 route.js 获得的 PropertyQR 数组复制到一个新的数组 PropertyTypeID 中,然后当表单提交时,我将表单中的选定值与我创建的键值数组名称字段进行比较,如果匹配,则获取 id 字段。
<script>
$(function () {
var propertyTypeID = [];
for(var i=0; i< <%= list.propertyQR.length%>; i++){
propertyTypeID.id.push(<%= list.propertyQR[i].id %>)
propertyTypeID.name.push(<%= list.propertyQR[i].name %>)
};
$('#submit-import-form').click(function(){
for(var i=0; i < propertyTypeID.length; i++){
if (tipoPropiedad==propertyTypeID[i].name)
propertyTID=propertyTypeId[i].id;
}
}
});
</script>
现在,当我尝试加载我得到的表单时:
未捕获的类型错误:无法读取未定义的属性“推送”
为什么会这样?请帮忙!!!!!!
【问题讨论】: