我正在使用Reactjs编写一个菜单组件.
"use strict";
var React = require("react");
var Menus = React.createClass({
item_url: function (item,categories,articles) {
console.log('afdasfasfasdfasdf');
var url='XXX';
if (item.type == 1) {
url = item.categoryId == null ? 'javascript:void(0)' : path('buex_portal_browse_category', {slug: categories[item.categoryId].slug});
} else if (item.type == 2) {
url = item.articleId == null ? 'javascript:void(0)' : path('buex_portal_view_article', {slug: articles[item.articleId].slug, id: item.articleId});
} else {
url = item.url;
}
return url;
},
render: function () {
// console.log(this.props.menus); // return correctly
var menuElements = this.props.menus.map(function (item1) { // …
Run Code Online (Sandbox Code Playgroud) 我正在努力将一些React应用分解为较小的组件。在分离代码之前,一切都按计划进行。我现在正在尝试调用一个函数onChange
,该函数先调用一个函数,然后再将其作为调用prop
。我正在像这样绑定函数,this.updateInput = this.updateInput.bind(this);
但是我仍然无法弄清缺少的内容。我在这里尝试了最近的文章(React:将功能传递给子组件),但错误仍然存在。任何帮助都很棒。
这是我正在使用的代码:
class Weather extends React.Component {
constructor(props) {
super(props);
this.state = {
city: '',
details: []
};
this.updateInputValue = this.updateInputValue.bind(this);
}
updateInputValue(e) {
this.setState({
city: e.target.value
});
console.log('hit')
}
render() {
return (
<div className={style.container + ' ' + style.bodyText}>
<WeatherForm
updateInput={this.updateInputValue}
/>
</div>
);
}
}
class WeatherForm extends React.Component {
constructor(props) {
super(props);
this.updateInput = this.updateInput.bind(this);
}
updateInput(e) {
this.props.updateInputValue(e);
}
render() {
return (
<div className={style.weatherForm}> …
Run Code Online (Sandbox Code Playgroud)