覆盖骨干的收藏取 [英] override Backbone's Collection-fetch

查看:111
本文介绍了覆盖骨干的收藏取的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个问题,那就是 - >我想在我的收藏非RESTful的方式,所以我决定重写Collection.fetch,这是

I got a problem,that is ->"I want to get my collection in a NON-RESTful way,so I decide to override the Collection.fetch,which is

    App.carClc = Backbone.Collection.extend({
    model : App.cardModel,
    url : 'http://localhost/bbtest/data.php',
    fetch : function() {
        $.ajax({
            type : 'GET',
            url : this.url,
            success : function(data) {
                console.log(data);
            }
        });
    }
});

问题是,我不知道怎么我的收藏设置的反应,我是新来BackboneJS,谢谢大家了!

the point is ,I don't know how to set my collection to the response,I'm new to BackboneJS,thanks all of you !

推荐答案

如果你想定制的装饰添加到,但不能完全覆盖它,试试

If you want to add a custom "decorator" to fetch, but not override it completely, try:

    var MyCollection = Backbone.Collection.extend({

        //custom methods

        fetch: function(options) {

            //do specific pre-processing 

            //Call Backbone's fetch
            return Backbone.Collection.prototype.fetch.call(this, options);
        }

  });    

在这里,你不必推出自己的 $。阿贾克斯

另外,不要,如果你想使用由骨干收益 $ C>方法。

Also, don't forget the return in the last line if you want to use the jQuery promise returned by Backbone's fetch method.

请参阅 HTTP://japhr.blogspot 。在/ 2011/10 /压倒一切的URL和取功能于backbonejs.html了解更多详情

这篇关于覆盖骨干的收藏取的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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