Skip to content

anonymous /app.js
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
How to use Twitter Typeahead with react
var states = ['Alabama', 'Alaska', 'Arizona', 'Arkansas', 'California',
'Colorado', 'Connecticut', 'Delaware', 'Florida', 'Georgia', 'Hawaii',
'Idaho', 'Illinois', 'Indiana', 'Iowa', 'Kansas', 'Kentucky', 'Louisiana',
'Maine', 'Maryland', 'Massachusetts', 'Michigan', 'Minnesota',
'Mississippi', 'Missouri', 'Montana', 'Nebraska', 'Nevada', 'New Hampshire',
'New Jersey', 'New Mexico', 'New York', 'North Carolina', 'North Dakota',
'Ohio', 'Oklahoma', 'Oregon', 'Pennsylvania', 'Rhode Island',
'South Carolina', 'South Dakota', 'Tennessee', 'Texas', 'Utah', 'Vermont',
'Virginia', 'Washington', 'West Virginia', 'Wisconsin', 'Wyoming'
];
var TypeaheadInput = React.createClass({
componentDidMount: function () {
$(this.refs.input.getDOMNode()).typeahead(
{ hint: true, highlight: true, minLength: 1 },
{ name: 'states', displayKey: 'value', source: substringMatcher(this.props.options)}
)
.on("typeahead:autocompleted",this.props.onAutocompleted);
},
render: function() {
return ( <input type="text" ref="input" /> );
}
});
var ExampleApplication = React.createClass({
render: function() {
var bls = function () { console.log("bla"); }
return (
<div>
<TypeaheadInput onAutocompleted={bls} options={states} />
</div>
);
}
});
React.renderComponent( <ExampleApplication />, document.getElementById('container'));
<!DOCTYPE html>
<html>
<head>
<meta http-equiv='Content-type' content='text/html; charset=utf-8'>
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Typeahead</title>
<script src="jquery-2.1.1.min.js"></script>
<script src="typeahead.jquery.min.js"></script>
</head>
<body>
<div id="container">
</div>
<script src="react-with-addons.min.js"></script>
<script src="JSXTransformer.js"></script>
<script type="text/jsx" src="app.js"></script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.