我在使用 MateriaUI 框架的 Textfield 中遇到了一个恼人的问题。我有一个包含许多输入的表单,在字段内输入或删除值时似乎有点滞后。在其他组件中,当有 2 或 3 个输入时,根本没有延迟。
编辑:问题似乎出在我的 onChange 处理程序上。
任何帮助深表感谢。提前致谢。
这是我的自定义输入代码:
import React, { useReducer, useEffect } from 'react';
import { validate } from '../utils/validators';
import TextField from '@material-ui/core/TextField';
import { ThemeProvider, makeStyles, createMuiTheme } from '@material-ui/core/styles';
import { green } from '@material-ui/core/colors';
const useStyles = makeStyles((theme) => ({
root: {
color: 'white'
},
input: {
margin: '10px',
'&& .MuiInput-underline:before': {
borderBottomColor: 'white'
},
},
label: {
color: 'white'
}
}));
const theme = createMuiTheme({
palette: { …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用 perlbrew 在我的 macOS 环境中安装 perl 版本 5.33.4。我无法理解为什么它在安装过程中失败。
我开始使用 安装\curl -L https://install.perlbrew.pl | bashperlbrew,然后在我的 zshenv 中添加了这一行:source ~/perl5/perlbrew/etc/bashrc并开始使用perlbrew install perl-5.33.4命令安装 perl 。我也尝试过不同的 perl 版本,但问题是一样的。
这是记录的错误:
# Failed test 20 - array should contain one result or more: libc => () at t/DynaLoader.t line 127
# got "0"
# expected >= "1"
../ext/DynaLoader/t/DynaLoader.t .....................................
Failed 1/44 subtests
Test Summary Report
-------------------
../ext/DynaLoader/t/DynaLoader.t (Wstat: 0 Tests: 44 Failed: 1)
Failed test: 20
Files=2652, Tests=1183275, 624 wallclock secs …Run Code Online (Sandbox Code Playgroud) 我在我的 React 项目中从 MaterialUI 导入了自动完成组件,并将其用作带有复选框的多选:https : //material-ui.com/components/autocomplete/#checkboxes
我注意到当我输入输入来过滤列表然后选择一个值时,用户插入的过滤器会重置。我想避免这种情况并继续使用过滤器进行多选,而不是每次都重新插入它。我没有在组件 API 中找到任何道具来解决这个问题。
有什么建议吗?
这是我的组件代码:
const VirtualAutocomplete = (props) => {
const classes = useStyles();
const textClasses = textStyles();
return (
<Autocomplete
id={props.id}
style={{ width: 'auto' }}
value={props.value}
limitTags={4}
noOptionsText="No records found."
classes={classes}
disableCloseOnSelect
ListboxComponent={ListboxComponent}
renderGroup={renderGroup}
onChange={props.onChange}
options={props.options}
filterOptions={startsWith}
multiple={props.multiple}
renderInput={(params) =>
<ThemeProvider theme={theme}>
<TextField {...params}
variant='outlined'
classes={{ root: textClasses.formControlRoot }}
InputLabelProps={{ classes: { root: textClasses.labelRoot } }}
label={props.label}
/>
</ThemeProvider>
}
renderOption={(option, { selected }) => (
<Fragment>
<Checkbox
icon={icon}
checkedIcon={checkedIcon} …Run Code Online (Sandbox Code Playgroud) 我有一个这样的数组:
const myArray = ['Item1', 'Item3', 'Item5'];
Run Code Online (Sandbox Code Playgroud)
和这样的对象列表:
ObjectsList: {
Item1: ["A", "B", "C"],
Item2: ["A", "D", "E"],
Item3: ["B", "E", "C", "G"],
Item4: ["B", "C", "R"],
Item5: ["D"],
Item6: ["F", "D", "E"],
Item7: ["A", "E", "L", "M"],
}
Run Code Online (Sandbox Code Playgroud)
我想获取与我的数组元素同名的所有键的值,并将它们推送到一个没有重复元素的新数组中。
在我提供的示例中,我想获取 Item1、Item3、Item5 键值并将它们推送到一个新数组中以避免重复。结果应该是:[A, B, C, E, G, D]
在 JavaScript 中执行此操作的最佳方法是什么?提前致谢。