videoSearch(term) { YTSearch( { key: apiKey, term: term }, (videos) => { this.setState({ videos, selectedVideo: videos[0] }) }); }
videoRequest: function(e, hash){ if(e) e.preventDefault(); let request = (!hash) ? this.$el.find('input[name="search"]').val(): this.hash; let router = new Marionette.AppRouter({}); router.navigate(request, {trigger: true, replace: true}); YTSearch({key: API_KEY, term: request}, (videos) => { if (!videos.length) return false; collection = []; for (let video in videos){ collection.push({ id: videos[video].id.videoId, title: videos[video].snippet.title, desc: videos[video].snippet.description, thumb: videos[video].snippet.thumbnails.default.url, }); } let collectionView = new VideoCollectionView({ collection: new Backbone.Collection(collection) }); let selectedView = new VideoSelected({model: new Backbone.Model(collection[0])}); layout = new VideoLayout().render(); App.mainRegion.show(layout); layout.showChildView('list', collectionView); layout.showChildView('selected', selectedView); }); }
videoSearch(term){ YTSearch({key: API_KEY, term:term}, (videos) => { this.setState({ videos: videos, }); }); }
videoSearch(term) { YTSearch({ term, key: API_KEY }, (videos) => { this.setState({ videos, selectedVideo: videos[0] }) }) }
onSearchBarChange(term){ YTSearch({ "key": API_KEY, "term": term }, function(data) { this.setState({videos: data, selectedVideo: data[0]}); }.bind(this)); }
videoSearch(term) { YTSearch({key: API_KEY, term: term}, (videos) => { this.setState({ videos: videos, selectedVideo: videos[0] }); }); }
videoSearch(term) { YTSearch({key: API_KEY, term: term}, videos => { this.setState({ videos: videos, selectedVideo: videos[0] // set initial video equal to first }) }); }
videoSearch(term) { YTSearch({key: API_KEY, term: term}, function(videos) { this.setState({ videos: videos, selectedVideo: videos[0] }); }.bind(this)); }
videoSearch(term) { YouTubeSearch({key: API_KEY, term: 'cats '+ term}, (videos) => { this.setState({ videos: videos, selectedVideo: videos[0] }); }); }
videoSearch(term) { YTSearch({key: API_KEY, term: term}, (data) => { this.setState({ videos: data, selectedVideo: data[0] }); }); }
videoSearch(searchTerm){ // performs a youtube search YTSearch({key: API_KEY, term: searchTerm}, (videos) => { // ES6 callback function (=>) for the youtube API. this.setState({ videos: videos, selectedVideo: videos[0] }); }); }
videoSearch(term){ YTSearch({key: API_KEY, term: term}, (videos) => { //update state with new list of videos this.setState({ videos: videos, selectedVideo: videos[0] }); }); }
_searchOnYT(term) { YTSEARCH({key:API_KEY,term:term},(videos) =>{ this.setState({ videos:videos, selectedVideo:videos[0] }); }); }
videoSearch(term) { YTSearch({key: API_KEY, term: term}, (videos) => { this.setState({ videos: videos, selectedVideo: videos[0] }); //ES6 allows compacting the syntax ({videos}) from ({videos: videos}) }); }
videoSearch(term) { YTSearch({key: API_KEY, term: term, maxResults: this.props.maxResults}, (videos) => { // same as this.setState({videos: videos}) using destructuring this.setState({ videos: videos, selectedVideo: videos[0] }); }) }
constructor(props) { super(props); this.state = {videos: [], selectedVideo: null}; YTSearch({key: API_KEY, term: 'meteorjs'}, (videos) => { this.setState({videos, selectedVideo: videos[0]}); }); }
videoSearch(term) { YTSearch({key: API_KEY, term: term}, (videos) => { this.setState({ videos: videos, selectedVideo: videos[0] }); // this.setState({ videos: videos }) = this.setState({videos}) -> ES6 syntax }); }
videoSearch(searchTerm) { YTSearch({key: API_KEY, term: searchTerm}, (videos) => { //this.setState({ videos: videos }); ====> this.setState({ videos }); this.setState({ videos: videos, selectedVideo: videos[0] }); }); }
this.getApiKey().then(apiKey => { // console.log("Key sent to YTSearch: ", apiKey); YTSearch({key: apiKey, term: searchTerm}, (videos) => { this.setState({ videos, selectedVideo: videos[0] }); }); })
videoSearch(searchTerm) { YTSearch({key: API_KEY, term: searchTerm}, (videos) => { //setting state forces a re-render this.setState({ videos: videos, selectedVideo: videos[0] }); }); }
videoSearch(user_search_term) { // 'key' and 'term' are properties of YTSearch YTSearch({key: API_KEY, term: user_search_term}, (videos) => { this.setState({ videos: videos, selectedVideo: videos[0] }) // In ES6, you can use a single variable name when the key AND value share the same name. This resolves to "this.setState({ videos: videos })" }); }
constructor(props){ super(props); this.state = { videos: [] }; YTSearch({key: API_KEY, term: 'HotS'}, (videos) => {this.setState({videos}); }); }
videoSearch(term) { YTSearch({key: API_KEY, term: term} , videos => { // this.setState({videos: videos}); this.setState({ videos: videos, selectedVideo: this.state.selectedVideo || videos[0] // 最初の動画は最初、その後は保持 }); }); }
videoSearch(term) { YTSearch({key: API_KEY, term: term}, (videos) => { this.setState({ videos: videos, selectedVideo: videos[0] // ES2016 version of this.setState({ videos: videos }) }); }); }
onVideoSearch(searchText){ this.setState( { searchText } ); YTSearch( { key: API_KEY, term: this.state.searchText }, (data) => { this.setState( { YTvideos: data } ); }) console.log(this.state.searchText); }
videoSearch(term) { YTSearch({key: API_KEY, term: term}, (videos) => { this.setState({ videos: videos, selectedVideo: videos[0] }); //this.setState({ videos: videos}); only works when key and value are the same }); }
videoSearchPage(token){ YTSearch({pageToken:token,term:this.state.currentTerm,key:API_KEY},(data) =>{ this.setState({ videos:data.items, selectedVideo:data.items[0], nextPageToken:data.nextPageToken?data.nextPageToken:'', prevPageToken:data.prevPageToken?data.prevPageToken:'' }); }); }
videoSearch(term){ var that = this; YTSearch({ key : API_KEY, term : term}, function(videos){ that.setState({ videos : videos, selectedVideo : videos[0] }); console.log(that.state.videos); }); }
videoSearch(term){ YTSearch({key: API_KEY, term: term}, (videos) => { // same ths as : this.setState({ videos: videos }); this.setState({ videos: videos, selectedVideo: videos[0] }); //console.log(this.state.videos); }); }
videoSearch(term){ YTSearch({term:term,key:API_KEY},(data) =>{ this.setState({ videos:data.items, selectedVideo:data.items[0], nextPageToken:data.nextPageToken?data.nextPageToken:'', prevPageToken:data.prevPageToken?data.prevPageToken:'', currentTerm:term }); }); }