我想做这样的事情
var App = React.createClass({
render: function() {
return (
<CountryAutoComplete />
)
}
});
不同的应用程序
var App2 = React.createClass({
render: function() {
return (
<CountryAutoComplete />
)
}
});
这是一个简单的自动完成(不是整个文件)
var AutoComplete = React.createClass({
componentDidMount: function() {
$(this.getDOMNode()).typeahead(this.props);
},
render: function() {
return (
<input type="text" class="typeahead" onChange={this.props.onChange} />
);
}
});
CountryAutoComplete 将是这样的自包含的东西。
var CountryAutoComplete = React.createClass({
search: function(country, process) {
// Make an ajax call and return the data. No other components needed
$.ajax({
url: '/country' + '?search=' + country
}).then(process);
},
render: function() {
return (
<AutoComplete onChange={this.props.onChange} source={this.search} />
);
}
});
根据 Flux 文档,看起来任何带有 API 调用的东西都需要通过
操作 -> API -> 调度程序 -> 商店 -> 组件
这使得 CountryAutoComplete 绑定到特定的应用程序,因为操作、调度程序和商店是特定于应用程序的。使该组件可跨应用程序重用的最佳方法是什么?