如何解决如何使本地推送的数组全局javascript
我在全局范围内最初将数组声明为空数组 然后在函数回调中。我必须将响应消息元素推送到此数组。
var array = []
frappe.call({
method: "frappe.client.get_list",args: {
doctype: 'Attendance',filters: [['attendance_date','>=',values.from_date],['attendance_date','<=',values.to_date]
]
},"callback": function (response) {
console.log(response.message)
for (var i in response.message) {
frappe.call({
method: "frappe.client.get_value",args: {
doctype: 'Attendance',fieldname: ['branch'],filters: { 'name': ['=',response.message[i].name] }
},"callback": function (data) {
frappe.call({
method: "frappe.client.get_value",args: {
doctype: 'Medical Crew Salaries',fieldname: ['total'],filters: { 'cost_center': ['=',data.message.branch]}
},"callback": function (r) {
array.push({ branch: data.message.branch,total: r.message.total })
}
})
}
})
}
}
})
console.log(array.length)
var result=[]
array.reduce(function(res,value) {
if (!res[value.branch]) {
res[value.branch] = { branch: data.message.branch,total: 0 };
result.push(res[value.branch])
}
res[value.branch].total += r.message.total;
return res;
},{});
console.log(result)
frappe.model.with_doctype('Journal Entry',function() {
var journal_entry = frappe.model.get_new_doc('Journal Entry');
for(var c in result){
var journalentry_account= frappe.model.add_child(journal_entry,'accounts');
journalentry_account.debit_in_account_currency=result[c].total
journalentry_account.cost_center=result[c].branch
}
frappe.set_route('Form','Journal Entry',journal_entry.name);
})
我需要这样做的原因是我需要在外面循环这个数组,第一个 for 循环数组。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。