Javascript 检查元素长度以标记状态布尔值
我在这个返回对象中指定默认值Javascript 检查元素长度以标记状态布尔值,javascript,arrays,reactjs,boolean,Javascript,Arrays,Reactjs,Boolean,我在这个返回对象中指定默认值checked false,请参见代码 return Object.assign(file, { temp_id: _.uniqueId(), checked: false, }) 我有一个例外,如果这是我的第一个文件被丢弃,我希望选中:true 我知道我的第一个文件是在 const filePosition=files.length返回0 如何将此条件应用于我的checked?如果我理解正确,您希望将checked更新为true如果file.len
checked false
,请参见代码
return Object.assign(file, {
temp_id: _.uniqueId(),
checked: false,
})
我有一个例外,如果这是我的第一个文件被丢弃,我希望选中:true
我知道我的第一个文件是在
const filePosition=files.length
返回0
如何将此条件应用于我的
checked
?如果我理解正确,您希望将checked
更新为true
如果file.length==0
和false
和file.length!==0
如果这是正确的,您可以执行以下操作:
return Object.assign(file, {
temp_id: _.uniqueId(),
checked: files.length === 0,
})