如果在下一个JS中,如何在内联内线循环中线
我想在bedsassign.map
内停止循环,如果row.id.id
不等于u.tenant_id
,但是放置break;
不起作用。
{tenants.map((row) =>
bedsAssign.map(
(u) =>
row.id !== u.tenant_id && (
<MenuItem key={row.id} value={row.id}>
{row.fullName}
</MenuItem>
break; --> not working
)
)
)}
I would like to stop the loop inside bedsAssign.map
if row.id
is not equal to u.tenant_id
but putting break;
doesn't work.
{tenants.map((row) =>
bedsAssign.map(
(u) =>
row.id !== u.tenant_id && (
<MenuItem key={row.id} value={row.id}>
{row.fullName}
</MenuItem>
break; --> not working
)
)
)}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以在
MAP
之前添加filter
,以删除所有bedsassign
与当前row.id.id
不匹配的项目,如果您想要打破循环,您可以尝试使用> 找到的 返回 for
map
You can add
filter
beforemap
to remove allbedsAssign
items which are not matched with currentrow.id
If you want to break the loop, you can try to use
some
orfind
with a properreturn
formap
您无法打破任何数组方法,例如foreach,filter,map等。如果遇到希望循环断裂的场景,则应将传统用于循环。
You can not break any array methods like forEach, filter, map etc. If you encounter a scenario where you want your loop to break then you should use traditional for loop.
使用
filter
而不是bedsassign的地图
:该过滤器将仅填充满足您想要的条件的项目。
编辑:我注意到您要在满足条件后打破,这将在这种情况下起作用:
use a
filter
instead ofmap
for bedsAssign:the filter is going to only fill in the items that are meeting the condition you want.
EDIT: I noticed that you want to break once condition is met, this would work in this case: