使用Backbone.js的摆脱ASMX数据与“D” [英] Using backbone.js to get data from ASMX with the 'd'
本文介绍了使用Backbone.js的摆脱ASMX数据与“D”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是pretty新骨干,我一直在试图创建一个与它自动填充功能,通过Web服务ASMX喂食。我似乎有问题是而在JSON我的web服务回报(经过一个痛苦的战斗吧),它包装在一个'D'响应(数据)。我如何获取视图来了解这一点,并在正确的数据得到什么?
I'm pretty new to Backbone and I've been trying to create autocomplete functionality with it, fed by an ASMX webservice. The issue I seem to have is whilst my webservice returns in JSON (after a painful battle with it), it wraps the response in a 'd' (dataset). How do I get the view to understand this and get at the correct data?
下面是我的code: -
Here is my code:-
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();
}
});
有人能看到我在做什么错?我已经在这里坐得太久了!
Can anyone see what I'm doing wrong? I've been sitting here for too long now!
帮助是AP preciated;)
Help is appreciated ;)
推荐答案
怎么样在你的 AirlineCollection
:
parse: function (response) {
return response.d;
}
这篇关于使用Backbone.js的摆脱ASMX数据与“D”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文