【发布时间】:2021-06-12 20:30:41
【问题描述】:
我想为每个部门添加不同的工作人员值,但将该值乘以另一个 key:value 属性。这是一个 Vue.js 组合 API webapp。
export default {
setup( props, {emit}) {
let data = reactive({
let chosenCompanies: [
{ id: 'Big', workers: 250, clones: 9 },
{ id: 'Medium', workers: 75, clones: 2 },
{ id: 'Small', workers: 10, clones: 6 },
{ id: 'Individual', workers: 1, clones: 7}
]
});
const employedWorkers = () => {
let employedworkersPrivate = 0;
data.chosenCompanies.forEach(function(sector){
for (const [key, value] of Object.entries(sector)) {
if (key === 'workers') {
employedworkersPrivate += parseInt(value)
// I need to multiply the number of workers per clones here, instead of just adding more workers
// can I get to the key 'clones' value here?
}
}
})
return employedworkersPrivate
}
}
}
【问题讨论】:
-
谢谢你,但我做了,只是我清理代码时忘记粘贴了
标签: javascript function loops vue.js vue-composition-api