这是我第一次涉足Backbone,我只想尝试从Dribbble获取一个Api调用.
我正试图以最主干的方式做到这一点.然而,它似乎在制作集合时做了一些有趣的事情.
我对此实际渲染并不感到困扰,我只是希望使用Api的每个响应的模型正确设置集合.
任何提示和方向都会很棒.我完全做错了吗?
我正在尝试使用backbones.js fetch从twitter搜索中获取json
我的代码可以告诉我哪里出错了?
(function($){
var Item = Backbone.Model.extend();
var List = Backbone.Collection.extend({
model: Item,
url:"http://search.twitter.com/search.json?q=blue%20angels&rpp=5&include_entities=true&result_type=mixed"
});
var ListView = Backbone.View.extend({
el: $('#test'),
events: {
'click button#add': 'getPost'
},
initialize: function(){
_.bindAll(this, 'render', 'getPost');
this.collection = new List();
this.render();
},
render: function(){
var self = this;
$(this.el).append("<button id='add'>get</button>");
},
getPost: function(){
console.log(this.collection.fetch());
}
});
// **listView instance**: Instantiate main app view.
var listView = new ListView();
})(jQuery);?
Run Code Online (Sandbox Code Playgroud)
我刚刚开始使用骨干,我只想在console.log中使用json
你可以在这看到我的例子.jsfiddle.net/YnJ9q/2/