Friday, May 30, 2014

Re: backbonejs and django

Hi sanjay,

Thanks for your reply,here is how I did it this way

$(function(){
        // event object
        var vent=_.extend({},Backbone.Events)

        // the model
        var myModel=Backbone.Model.extend();

        // the model collection
        var myModelCollection=Backbone.Collection.extend({
            model:myModel,
            urlRoot: 'resp',
            initialize:function(){
                this.fetch({
                    success:function(){
                        vent.trigger('fetched')
                    }
                })
            },
        });

        // one model view
        var myModelView=Backbone.View.extend({
            tagName:'p',
            template:_.template($('#demotpl').html()),
            initialize:function(){
                //this.render()
            },
            render:function(){
                this.$el.html(this.template(this.model.toJSON()));
                return this;
            },
        });


        // model collection view
        var myModelCollectionView=Backbone.View.extend({
            el:'.demo',
            initialize:function(){
                vent.on('fetched',this.render,this)
                //this.render()
            },
            render:function(){
                this.collection.each(this.one,this)
            },
            one:function(onemod){
                var onemodView=new myModelView({model:onemod})
                console.log(onemod)
                this.$el.append(onemodView.render().el)
            }
        });

        // initialize the collection
        var newCollection=new myModelCollection()

        // initaliaze collection view
        var newCollectionView=new myModelCollectionView({collection:newCollection})
});


is there another way i could have done it?

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/b812a380-47a6-40b6-b581-d00b6955f75b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment