運行應用程序時我沒有得到,它只發生在我運行測試時。基本上我現在寫了快照測試。TypeError:無法讀取未定義的屬性'長度'
TypeError: Cannot read property 'length' of undefined at Papertype.render (src/components/layoutcomponents/papertype.js:50:23)
以下是在papertype.js
import React, { Component } from 'react';
import common from '../../jsons/common.json';
import catalogSpecs from '../../jsons/infiniti.json';
class Papertype extends Component {
constructor(props) {
super(props);
this.state = {
paperType: "Regular",
regularPaper : true,
heavyPaper : false
}
}
changePaperTypeLayoutParams(event){
let nameSelection = event.target.value;
let lalala = catalogSpecs.commonProps.paperType.paperTypeDefinitionDTOs
let paperTypebinding = lalala[nameSelection].absolutelayflat;
let paperLaminationVisibility = lalala[nameSelection].paperLamination;
this.setState({
paperType: nameSelection
});
if(nameSelection.indexOf("Regular")>-1 ||
nameSelection.indexOf("Metallic")>-1){
this.setState({
regularPaper : true,
heavyPaper : false
});
this.props.setRegularOrHeavy(true,false,paperTypebinding,paperLaminationVisibility);
}else{
this.setState({
heavyPaper : true,
regularPaper : false
});
this.props.setRegularOrHeavy(false,true,paperTypebinding,paperLaminationVisibility);
}
}
render() {
let validLayoutPaperType=this.props.validLayoutPaperType;
let paperTypeOptions = [];
let paperTypeOpts = common.paperTypeOpts;
for(let i=0;i<validLayoutPaperType.length;i++){
let paper = paperTypeOpts[validLayoutPaperType[i]]
paperTypeOptions.push(<option label={paper} value={paper} key={i}>{paper}</option>)
}
return(
<div className="layout-item">
<label>Paper Type</label>
<div className="custom-select">
<select className="form-control" onChange={this.changePaperTypeLayoutParams.bind(this)}>
{paperTypeOptions}
</select>
<i className="icon icon-angle-down"></i>
</div>
</div>
)
}
}
export default Papertype;
在渲染中嘗試'console.log(this.props.validLayoutPaperType)'。 – Andrew