骨干取得成功,模型不安慰

时间:2013-01-27 05:14:44

标签: backbone.js backbone-views

使用fetch方法,我从我当地的json获得模型,但是成功了,没有什么可以安慰我..

我的代码上的任何问题......我调用渲染函数的方式在成功时是否正确?

我使用JSON:

[
    {'name':'student1'},
    {'name':'student2'},
    {'name':'student3'}
];

我的代码:

$(document).ready(function(){

    var school = {};

    school.model = Backbone.Model.extend({
        defaults:{
            name:'name yet to decide'    
        }    
    });

    school.collect = Backbone.Collection.extend({
        model:school.model,
        url:'js/school.json',
        initialize:function(){
            console.log(this.collection)//shows the undefined
        }
    });

    school.view = Backbone.View.extend({
        initialize:function(){
            var that = this;
            this.collection = new school.collect;
            this.collection.fetch({
                success:function(model,response){       
                    console.log(model,response);//i am not get any mode or response here
                    that.render(); //not at all calling..
                }
            });
        },
        render:function(){
            console.log('hi')
        }
    });

    var newModel = new school.model;

    var newSchool = new school.view({model:newModel});

})

0 个答案:

没有答案