将数据从数据库推送到数组后调用另一个javascript函数
我有一段代码,从db中检索数据,然后在angularJS脚本中放入数组将数据从数据库推送到数组后调用另一个javascript函数,javascript,arrays,Javascript,Arrays,我有一段代码,从db中检索数据,然后在angularJS脚本中放入数组 if(type == 'createSupplierInvoice'){ vm.data.organization = {}; vm.data.organization.selected = { name: result.data.name, id: result.data.organization_id
if(type == 'createSupplierInvoice'){
vm.data.organization = {};
vm.data.organization.selected = {
name: result.data.name,
id: result.data.organization_id
}
vm.data.ship_request_id = result.data.ship_request_id;
vm.data.terms = Number(result.data.payment_terms);
if(result.products.length > 0){
for(var i = 0;i<result.products.length;i++){
vm.products.push({
id: result.products[i].id,
product_id: result.products[i].ship_product_id,
code : result.products[i].ship_product_code,
description : result.products[i].ship_product_description,
request_quotation_detail_id : result.products[i].ship_request_quotation_detail_id,
qty : result.products[i].qty,
price : result.products[i].price,
total_price : result.products[i].total_price,
remarks : result.products[i].remarks,
temp_tax : 0,
temp_total: 0,
temp_subtotal: 0,
});
}
}
for(var d = 0; d < vm.products.length; d++){
calculateTotal(vm.products[d]);
console.log(vm.products[d]);
}
}
if(类型==“createSupplierInvoice”){
vm.data.organization={};
vm.data.organization.selected={
名称:result.data.name,
id:result.data.organization\u id
}
vm.data.ship\u request\u id=result.data.ship\u request\u id;
vm.data.terms=编号(结果、数据、付款条件);
如果(result.products.length>0){
对于(var i=0;i您在哪一点声明了您的函数?您的函数是否附加到作用域?如果您在声明之前调用函数,我猜会出现问题
我尝试了一个示例代码,效果很好
var a=[
{'name':'jack','age':23},
{'name':'jones','age':24}
]
var calculateTotal= function(items){
console.log(items);
}
for(var d = 0; d < a.length; d++){
calculateTotal(a[d].name);
console.log(a[d].name);
}
var a=[
{'name':'jack','age':23},
{'name':'jones','age':24}
]
var calculateTotal=功能(项目){
控制台日志(项目);
}
对于(var d=0;d
您在哪一点声明了您的函数?您的函数是否附加到作用域?如果您在声明之前调用函数,我想会出现问题
我尝试了一个示例代码,效果很好
var a=[
{'name':'jack','age':23},
{'name':'jones','age':24}
]
var calculateTotal= function(items){
console.log(items);
}
for(var d = 0; d < a.length; d++){
calculateTotal(a[d].name);
console.log(a[d].name);
}
var a=[
{'name':'jack','age':23},
{'name':'jones','age':24}
]
var calculateTotal=功能(项目){
控制台日志(项目);
}
对于(var d=0;d
控制台中有错误吗?没有,先生..完全没有错误。一切正常控制台中有错误吗?没有,先生..完全没有错误。你可以在使用函数后声明函数,因为函数声明被提升到函数的开头。你可以在使用函数后声明函数,因为函数声明e提升到功能的开始