[英]Get newly added object in Material-ui Autocomplete component
I'm using material-ui Autcomplete component with multiple
selection.我正在使用具有
multiple
选择的material-ui 自动完成组件。 And for one of the scenario, I need to get the value for newly added item.对于其中一种情况,我需要获取新添加项目的价值。 When I'm using
onChange
listener, it is giving me all the values selected in Autocomplete input.当我使用
onChange
侦听器时,它会为我提供在自动完成输入中选择的所有值。 Is there any way to get only added or removed one?有没有办法只添加或删除一个?
Codesandbox - https://codesandbox.io/s/xqex8?file=/demo.js Codesandbox - https://codesandbox.io/s/xqex8?file=/demo.js
according to the doc, the onChange funct receive three properties, called event
, value
, and reason.根据文档, onChange 函数接收三个属性,称为
event
、 value
和 reason。 You can receive the value of newly added item by taking advantage of event.target.textContent
as below:您可以利用
event.target.textContent
接收新添加项的值,如下所示:
onChange={(event, value) =>
console.log(
top100Films.filter(
(el, id) => el.title === event.target.textContent
)
)
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.