简体   繁体   English

如何在 map 数组方法中加入逻辑。 我已将标题作为道具发送,除了道具标题我想呈现其他标题

[英]how can I put a logic in map array method. I have sent title as props and except props title I want to render other title

这是我的代码。当我使用 map 方法时,它会映射虚拟数据中的每个标题

在这里,当我点击比特币时。父组件发送比特币作为标题。我不想在选择标签中包含比特币。 Here, when I click bitcoin.在这里,当我点击比特币时。 Parent component sends bitcoin as title.父组件发送比特币作为标题。 I don't want to include bitcoin in the select tag.我不想在 select 标签中包含比特币。

You are returning the option directly from your map function, if you want to add logic inside just add {} and a return statement inside您直接从 map function 返回选项,如果您想在里面添加逻辑,只需添加{}和里面的return语句

{coins.map((item) => {
    // you can put your logic here
    // for example just first 2 letters
    const customTitle = item.title.slice(0, 2)
    return (
        <option>{customTitle}</option>
    )
})}

You can read more about arrow functions here您可以在此处阅读有关arrow functions的更多信息

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我的数据库中有两个标题,并且有一个while循环,我想显示多折叠标题,数据库中我有多少标题记录 - I have two title in my database and I take a while loop, I want to display multi collapse title how much that I have title records in database 如何在JavaScript中将名称放入标题大小写? - How can I put names into title case in JavaScript? 如何使用XSLT和jQuery在书中获得动态标题? - how i can have a dynamically title in a book with XSLT and jQuery? 刷新时如何更改网页的标题? - How can I have the title of a webpage change when it is refreshed? 如何从数组数组中过滤和删除标题类别? - How Can I filter and remove title Categories from array of array? {props.props.title}? 为什么不{props.title}? - {props.props.title}? Why not {props.title}? 如何找到数组[{title:&#39;ccc&#39;},{title:&#39;abc&#39;},{title:&#39;ddd&#39;,}]中的&#39;abc&#39; - how do I find 'abc' is in the array [{title:'ccc'},{title:'abc'},{title:'ddd',}] 如何使用Angular从数组中提取特定标题? - How can I pull a specific title from an array using Angular? 如何使用道具传递地图数据 - How can I pass map data with props 我怎样才能 map 特定道具到 state? - How can I map specific props to state?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM