如何在jxs的下拉列表中打印?实际上我有下拉列表,通过这段代码我可以在点击它的同时将所有数据放在一行中,但我希望它在列表中。任何人都可以帮我解决这个问题吗?
我的代码:
comboClick () {
var apiBaseUrl = "http://api.eventsacross-stage.railsfactory.com/api/";
var input = this.state.search_event;
let self = this;
let location = [];
let cityArray = [];
axios.get(apiBaseUrl+'v1/events/?on_dashboard=false'+input)
.then(function (response) {
let events = response.data.events;
for(var i = 0; i < response.data.events_count; i++) {
var obj = response.data.events[i];
location.push(obj.locations[0].city);
}
let cityUnique = _.uniq(location, 'city');
cityArray.push(cityUnique);
self.setState({cityArray: cityArray});
})
.catch(function (error) {
console.log(error);
});console.log("cityArray",cityArray);
}
jsx part:
render() {
var cityFilter = [this.state.cityArray ? this.state.cityArray[0] : null];
{console.log("cityFilter",cityFilter)}
return (...
<div className="dropdown text-center">
<button
className="btn btn-default dropdown-toggle"
type="button"
data-toggle="dropdown"
style={{width: "50%"}}
onClick={this.comboClick.bind(this)}>
Place
<span className="caret"></span>
</button>
<ul className="dropdown-menu">
{cityFilter.map(function(city, index){
return <li className="text-center" key={ index }>{city}</li>;
})}
</ul>
</div>
...}