我對Backbone非常陌生,我一直在嘗試使用ASMX web服務創建自動完成功能。我似乎遇到的問題是,雖然我的web服務在JSON中返回(經過與它的痛苦戰鬥),但它將響應包裝在'd'(數據集)中。我如何才能理解這一點並獲取正確的數據?使用backbone.js從'ASMX'獲取數據'd'
這裏是我的代碼: -
var Airline = Backbone.Model.extend({
initialize: function() {},
defaults: {
name: 'Airline Name',
rating: 50,
icon: '/blank.png'
}
});
var AirlineCollection = Backbone.Collection.extend({
model: Airline,
contentType: "application/json",
url: '/ControlTower/public/runway.asmx/all-airlines',
parse: function (response) {
return response;
}
});
var SelectionView = Backbone.View.extend({
el : $('#airline'),
render: function() {
$(this.el).html("You Selected : " + this.model.get('AirlineName'));
return this;
},
});
var airlines = new AirlineCollection();
airlines.fetch({async: false, contentType: "application/json" });
var airlineNames = airlines.pluck("AirlineName");
$("#airline").autocomplete({
source : airlineNames,
minLength : 1,
select: function(event, ui){
var selectedModel = airlines.where({name: ui.item.value})[0];
var view = new SelectionView({model: selectedModel});
view.render();
}
});
有人能看到我在做什麼錯?我一直坐在這裏太久了!
幫助表示讚賞;)
閱讀本 - HTTP:/ /encosia.com/a-breaking-change-between-versio ns-of-aspnet-ajax/ – 2012-08-07 11:34:42