私はbackbone.jsアプリで問題に直面しています:JSON Webサービスからデータをフェッチしようとしていますが、GET HTTPリクエストは成功します(Chromeの開発者コンソールを調べました)が、バックボーンフェッチはエラーをトリガーし、モデルを更新しません。
ここでコードを見ることができます: https ://github.com/tdurand/faq-app-client-mobile
そして、アプリを実行して、ここでデバッグを試みることができます:http: //tdurand.github.com/faq-app-client-mobile/
JSONフィードは次のようになります
[
{
"title":"Probleme ou Bug",
"desc":"Pour les problemes ou les bugs rencontrés",
"entries":[
{
"title":"testdqs",
"desc":"testqsdqs"
}
]
}
]
私のコレクションモデルは次のとおりです。
var Categories = Backbone.Collection.extend({
url:"http://cryptic-eyrie-7716.herokuapp.com/faq/fr",
model:Category,
parse:function(response) {
console.log("test")
console.log(response);
return response;
},
sync: function(method, model, options) {
var params = _.extend({
type: 'GET',
dataType: 'jsonp',
url: model.url,
processData:false
}, options);
return $.ajax(params);
},
});
そして私の見解:
var IndexView = Backbone.View.extend({
el: '#index',
initialize:function() {
Categories.fetch({
success: function(m,r){
console.log("success");
console.log(r); // => 2 (collection have been populated)
},
error: function(m,r) {
console.log("error");
console.log(r.responseText);
}
});
Categories.on( 'all', this.render, this );
},
//render the content into div of view
render: function(){
//this.el is the root element of Backbone.View. By default, it is a div.
//$el is cached jQuery object for the view's element.
//append the compiled template into view div container
this.$el.html(_.template(indexViewTemplate,{categories:Categories}));
//Trigger jquerymobile rendering
$("#index").trigger('pagecreate');
//return to enable chained calls
return this;
}
});
return IndexView;
あなたの助けをどうもありがとう