我使用React编写此演示。我使用Webpack来构建这个演示。当我开始演示时,错误将显示给我。
错误:
未捕获的TypeError:超级表达式必须为null或函数,而不是未定义的
var data = { "challengeSelectInfo" : [ {"mob_0" : "xxxxx1211"},
{"mob_1" : "xxxxx1211"}, {"mob_2" : "xxxxx1211"} ]}
$scope.radioGrp = (data['challengeSelectInfo'] || []).map(function(obj){
for(var i in obj){
return { 'value': i, 'name': obj[i] };
}
});
<input type="radio" ng-repeat="rb in radioGrp" ng-value="rb.value" ng-modal="radioValue" name="{{rb.name}}">
我不知道如何解决这个问题。
答案 0 :(得分:1)
您的代码中唯一的警告是由于您没有扩展正确的类,您需要扩展React.Component
。
class App extends React.Component {
constructor(props){
super(props);
this.handleClick = this.handleClick.bind(this);
}
handleClick(){
if(this.myTextInput !=null) {
this.myTextInput.focus();
}
}
render (){
return (
<div>
<input type="text" ref={(ref) => this.myTextInput = ref} />
<input type="button"
value="'Focus the text input"
onClick={this.handleClick}
/>
</div>
);
}
}
ReactDOM.render(<App />, document.getElementById('app'));
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/0.14.8/react.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/0.14.8/react-dom.min.js"></script>
<div id="app"></div>
答案 1 :(得分:0)
尝试以下:
import React, {Component} from 'react';
import ReactDOM from 'react-dom';
class App extends React.Compoment {
constructor(props){
super(props);
this.myTextInput = this.myTextInput.bind(this);
this.handleClick = this.handleClick.bind(this);
}
handleClick(){
if(this.myTextInput !=null) {
this.myTextInput.focus();
}
}
render (){
return (
<div>
<input type="text" ref={(ref) => this.myTextInput = ref} />
<input type="button"
value="'Focus the text input"
onClick={this.handleClick}
/>
</div>
);
}
}
ReactDOM.render(<App />, document.getElementById('app'));