V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX  ›  particlec  ›  全部回复第 37 页 / 共 37 页
回复总数  724
1 ... 28  29  30  31  32  33  34  35  36  37  
console.log(temporaryArr);
temporaryArr =['a1k8ySyJMPn', 'a1mXxl1AJOa', 'a1T2vgkO3L7', 'a1xaURWP4fN', 'a1oCgqebiVr', 'a1OSLcORuwH', 'a1StepeOwMD', 'a1oAnKZ7Clp', 'a1M4rSzH9wr', 'a1Y2RSRhB8b']
setSelectProductKey(temporaryArr) state 不是会指向 temporaryArr 吗?为啥会指向新数组呢
const [selectProductKey, setSelectProductKey] = useState([]);

// 这是一个搜索框的功能,通过 key 模糊筛选
const matchProductKey = key => {
let temporaryArr = [...productKeyArr];
// 这里 使用了 filter ,按道理原数组 temporaryArr 不会被改变
temporaryArr.filter(obj => obj.slice(key) !== -1);
// 如果原数组没有改变 selectProductKey 也不会改变
setSelectProductKey(temporaryArr);
};


matchProductKey(e);


// 但是实际界面 这里 selectProductKey 确实数据过滤了
{selectProductKey.map(key => (
<Select.Option value={key}>{key}</Select.Option>
))}
重新描述一下,第一次发帖问题顺序有点乱
// 这里 使用了 filter ,按道理 temporaryArr 不会被改变
temporaryArr.filter(obj => obj.slice(key) !== -1);

// selectProductKey 按道理也不会改变啊
setSelectProductKey(temporaryArr);
1 ... 28  29  30  31  32  33  34  35  36  37  
关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   2579 人在线   最高记录 6679   ·     Select Language
创意工作者们的社区
World is powered by solitude
VERSION: 3.9.8.5 · 15ms · UTC 09:07 · PVG 17:07 · LAX 02:07 · JFK 05:07
Developed with CodeLauncher
♥ Do have faith in what you're doing.