1
我一整天都在这里,显然这里有一些基本的错误,请帮我理解它是什么。Ember上下文的错误理解
我试图创建一个YouTube播放列表应用程序,作为第一步我试图搜索YouTube的相关视频,并返回结果到我的模型这条路线。
我唯一知道的肯定是搜索功能工作正常,因为我从另一个项目中拿走了。也有一些是错误的,我把值代入模型的方式..
这是我走到这一步:
app.js
App = Ember.Application.create({});
App.Router.map(function() {
this.resource('SearchYT');
this.resource('Play');
});
App.IndexRoute = Ember.Route.extend({
redirect : function() {
this.transitionTo('SearchYT');
}
});
App.SearchYTRoute = Ember.Route.extend({
model : function() {
return App.Video.all();
}
});
App.Video = Ember.Object.extend({
title : null,
seconds : null,
yid : null
});
App.Video.reopenClass({
// there are no videos initially
content : [],
// Searching flag
isSearching : false,
actions : {
makeSearch : function() {
console.log('working1');
// Start searching and remove existing results
this.set('isSearching', true);
this.set('content', []);
var query = this.get('searchString');
var c = $.getJSON("http://gdata.youtube.com/feeds/api/videos", {
alt : 'json',
'max-results' : 10,
v : 2,
q : query
});
c.success(function(data) {
var entries = data.feed.entry, results = [];
for (var i = 0; i < entries.length; i++) {
var e = entries[i];
results.push(App.Video.create({
yid : e.id.$t.split(':')[3],
seconds : parseInt(e.media$group.yt$duration.seconds),
title : e.title.$t
}));
}
this.set('content', results);
});
c.complete(function() {
this.set('isSearching', false);
});
}
}
});
请帮助我理解我的问题,谢谢 提前。
非常感谢您的回复!它仍然剂量工作虽然..现在它告诉我以下几点: 处理路由时:SearchYT undefined不是一个函数TypeError:undefined不是函数 – 2014-11-02 17:15:55
'all'没有在App.Video上定义。你正在调用'App.Video.all()',但你从来没有定义过'all'。 – Kingpin2k 2014-11-02 17:32:05
所以基本上改变它的内容应该做的伎俩? – 2014-11-02 17:34:57