Fetch不返回任何内容,模型实例为null

时间:2013-12-05 15:03:55

标签: javascript rest backbone.js firebase

有人可以向我解释为什么我的提取调用不会返回任何数据...我的帖子模型也会显示为无..这是正常的:/?

$(function() {

    //Set firebase URL
    var base_url = "https://xxx.firebaseio.com";
    function firebaseUrl (uri) {
        return base_url + uri + '.json';    
    }

    var Post = Backbone.Model.extend({
        defaults: {
            title: null,
            date: null,
            content: null
        },
        url: function() {
            var withId = firebaseUrl('/posts/' + this.id);
            var noId   = firebaseUrl('/posts');
            return this.id ? withId : noId ;
        }
    });

    var Posts = Backbone.Collection.extend({
        model: Post,
        url: function() {
            return firebaseUrl('/posts');
        }
    });

    var posts = new Posts;

    console.log(posts);

    posts.fetch({
        success: function() {
            posts.each(function(post) {
                console.log(post.get("title"));
            });
        }
    });


});

0 个答案:

没有答案