gpt4 book ai didi

javascript - 如何向数组添加动态变量?

转载 作者:行者123 更新时间:2023-12-02 21:59:29 24 4
gpt4 key购买 nike

我需要动态插入一个数组(=> inputClasses) String (=> 'Invalid'),它实际上是CSS中的一个类。然后从HTML标签中将它们两个一起读取。问题是他两个都不给我。我的错误是什么?

import React from 'react';
import './Input.css';

const input = (props) => {
let inputElement = null;
const inputClasses = ['InputElement'];

if (props.invalid) {
inputClasses.push('Invalid');
}

switch (props.elementType) {
case ('input'):
inputElement = <input
className={inputClasses.join()} <---------- Here he does not give me both
{...props.elementConfig}
defaultValue={props.value}
onChange={props.changed} />;
break;
case ('textarea'):
inputElement = <textarea
className={inputClasses.join()} <---------- And Here he does not give me both
{...props.elementConfig}
defaultValue={props.value}
onChange={props.changed} />;
break;
case ('select'):
inputElement = (
<select
className={inputClasses.join()} <---------- And Here he does not give me both
defaultValue={props.value}
onChange={props.changed}>
{props.elementConfig.options.map(option => (
<option key={option.value} defaultValue={option.value}>
{option.displayValue}
</option>
))}
</select>
);
break;
default:
inputElement = <input
className={inputClasses.join()} <---------- And Here he does not give me both
{...props.elementConfig}
defaultValue={props.value}
onChange={props.changed} />;
}

return (
<div className="Input">
<label className="Label">{props.label}</label>
{inputElement}
</div>
);
};

export default input;

我很感激每一个答案!谢谢

最佳答案

类名之间必须有空格,而不是逗号

inputClasses.join(' ')

关于javascript - 如何向数组添加动态变量?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59917305/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com