AJAX调用的支柱 - 此后渲染视图 [英] Ajax Calls in BackBone - And rendering the View thereafter

查看:115
本文介绍了AJAX调用的支柱 - 此后渲染视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个手风琴样的用户界面,其中对于用户有几个节点单击并展开的。在这些节点的点击,我需要做一个Ajax调用我的一个服务器端programs.The这里的想法是拨打电话,并听取成功或失败,要么情况下,我认为需要在模型对象返回挑选并随后传递到下划线模板来正确显示的值。

I do have an accordion kind of UI, where for a user there are several nodes to click and expand. On the click of those Nodes,I need to make an Ajax call to one my server side programs.The idea here is make the call, and listen for success or failure and either case , return back with the Model Object that my view needs to pick and subsequently pass to the Underscore template to display the values appropriately.

没有写骨干Ajax调用之前,所以有兴趣的专家那里知道,对于一个给定所需要的应该是我的最佳策略。

Haven't written a BackBone Ajax call before, and so was interested knowing from experts there, for a given need what should be my best strategy.

您的答案是多少AP preciated。

Your answers are much appreciated.

沙拉德

推荐答案

您有2个选项它们基本上是等价的,取决于味道。使用回调:

You have 2 options which are basically equivalent and depend on taste. Using callbacks:

myModel.fetch({
  success: function(model, response, options){
    // create and display new view
  },
  error: function(model, response, options){
    // display error
  }
});

或者用deferreds是等效的:

Or the equivalent using deferreds:

myModel.fetch().done(function(){
  // create and display new view
}).fail(function(response){
  // display error
});

这篇关于AJAX调用的支柱 - 此后渲染视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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