reactjs - ReactJs TypeError:映射时无法读取null的属性(读取'localeCompare')
问题描述
所以这个问题出现在昨天,前一秒一切正常,在这个页面上根本没有工作,然后突然我得到一个错误。
这是我们的 IOperator
class IOperator {
public id: string = '';
public operatorName: string = '';
public groupEmail: string = '';
public contacts: IContact[] = [];
public regions: IRegion[] = [];
public erpId: string = '';
public groupEmails: IGroupEmail[] = [];
public effectiveDate: string = '';
public billingAddress: string = '';
public billingCityStateZip: string = '';
}
我们正在做的是像往常一样在页面顶部的 IOperator 中设置我们的运算符。
Import { IContractor, IEngineer, IOperator, IRegion,
IWarehouse, IWell } from
'../../../../Interfaces/WellInterface';
private contractors: IContractor[] = [];
private engineers: IEngineer[] = [];
private operators: IOperator[] = [];
private warehouses: IWarehouse[] = [];
private counties: any[] = [];
private usStates: any[] = [];
public newEngineer: IEngineer = new IEngineer();
// disposers
public wellDisposer: any;
public warehouseDisposer: any;
public operatorDisposer: any;
public regionDisposer: any;
public contractorDisposer: any;
public engineersDisposer: any;
public statesDisposer: any;
public countiesDisposer: any;
private targetFormationDisposer: any;
public state = {
addEngineerModal: false,
contractorList: this.contractors,
countyList: this.counties,
dataSet: this.dataSet,
engineerList: this.engineers,
formIsValid: false,
isDirty: false,
newEngineer: this.newEngineer,
newWell: false,
novaEmailList: [],
operatorList: this.operators,
regionList: [] as IRegion[],
然后在下面,我们映射名称并使用 localeCompare 对字符串进行排序
<Col md="6">
<FormGroup className="required">
<Label>Operator</Label>
{/* invalid={this.state.well.operator.id === ""} */}
<EInput
type="select"
name="operator"
id="operator"
required={true}
value={this.state.well.operator.id}
onChange={this.handleOperatorChange}
disabled={this.state.well.id !== ""}
>
<option />
{this.state.operatorList.sort((a, b) => a.operatorName.localeCompare(b.operatorName)).map((operator: IOperator, index: number) =>
<option key={operator.id} value={operator.id}>{operator.operatorName}</option>
)}
</EInput>
</FormGroup>
</Col>
关于为什么会中断以及为什么会突然发生的任何想法?
解决方案
推荐阅读
- sharepoint - SharePoint Online 每日清单表格
- antlr4 - 如何抑制antlr4中生成的语法警告
- java - 无法确定 Instant 的数据类型
- python - Python:使用 sudo 调用 C 函数
- apache-spark - 获取RDD读取路径中的文件数
- npm - 在 Git LFS 中跟踪包锁定文件(例如 NPM 的 package-lock.json)是一个好主意吗?
- python - Python将numpy数组序列化为字节串
- laravel - 如何在资源集合中构建数据?
- java - 在 InheritanceType.JOINED 中使用 AttributeConverter 映射 MySQL ENUM 在 Hibernate 5.3.6 (JPA 2.1+) 上抛出 IllegalArgumentException:没有枚举常量
- snowflake-cloud-data-platform - 如何在雪花中检索序列的增量?