骨干 - 调用获取成功后回调不归路 [英] backbone - no return after calling fetch success callback

查看:76
本文介绍了骨干 - 调用获取成功后回调不归路的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

新手这里backbonejs。想知道是否有人能帮助我同样的问题。我尝试了上述解决方案,仍然没有运气。我有同样的问题,因为这个帖子<一个href=\"http://stackoverflow.com/questions/10925670/backbone-js-getting-json-back-from-url/32017266\">Backbone.js - 从网址获取JSON回来

这是我的code

  //模型新闻稿
  VAR NewsItem = Backbone.Model.extend({
  |默认值:{
  | | releaseID:不releaseID的时刻,
  | |日期:没有日期的那一刻',
  | |标题:没有标题的时刻
  |}
  });  //收集我们的模型
  VAR NewsItems = Backbone.Collection.extend({
  |型号:NewsItem,
  |网址:网址+/thewheelsonthebus.php
  |解析:功能(响应){
  | |的console.log(响应);
  | |返回响应;
  |}
  });  变种E =新NewsItems();
  e.fetch({
  |成功:函数(收集,响应){
  | |的console.log('这应该返回控制台上的东西'+响应);
  |}
  });


解决方案

由于@Wracker解决这是我打电话的回报和Ajax调用XML数据想不通输出格式..修复这是

在默认情况下的文件类型为自动检测到,但也许在这种情况下,它的失败在找出正确的格式。因此,我想尝试明确定义文件类型为XML / XTHML /脚本...

  this.fetch({
  数据类型:XML,
  异步:真实,
  成功:函数(收集,XML){} ....
});

但也有一个陷阱,你必须分析输出成一个典型的JavaScript对象。 (jQuery.parseXML()可能会派上用场在这种情况下)

newbie in backbonejs here. was wondering if anyone can help me with the same issue. i tried the solution above and still no luck. i am having the same issue as this post Backbone.js - Getting JSON back from url.

here is my code

  // Model for News Releases
  var NewsItem = Backbone.Model.extend({
  ¦ defaults: {
  ¦ ¦ releaseID: 'no releaseID at the moment',
  ¦ ¦ date: 'no date at the moment',
  ¦ ¦ title: 'no title at the moment'
  ¦ }
  });

  // Collection for our Model
  var NewsItems = Backbone.Collection.extend({
  ¦ model: NewsItem,
  ¦ url: url + "/thewheelsonthebus.php",                                 
  ¦ parse: function(response) {                                          
  ¦ ¦ console.log(response);                                             
  ¦ ¦ return response;                                                   
  ¦ }                                                                    
  });                                                                    

  var e = new NewsItems();                                               
  e.fetch({                                                              
  ¦ success: function(collection, response) {                            
  ¦ ¦ console.log('this should return something on console' + response); 
  ¦ }                                                                    
  });                                         

解决方案

Thanks to @Wracker the solution to this was I was calling an XML data in return and the ajax call can't figure out the output format.. the fix to this is

By default the fileType is automatically detected but perhaps in this case it's failing at figuring out the correct format. Therefore I'd try defining the fileType explicitly to xml/xthml/script...

this.fetch({ 
  dataType: "xml", 
  async: true, 
  success: function(collection, xml) { .... }
});

But there is also one catch, you have to parse to output into a typical javascript object. (jQuery.parseXML() may come in handy in such case)

这篇关于骨干 - 调用获取成功后回调不归路的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆