To be or not to be.That is a question!

---源于莎士比亚的《哈姆雷特》

导航

Backbone 学习2

(function($){
    var ListView=Backbone.View.extend({
        el:$("body"),
        events:{
            "click button#add":"addItem"
        },
        initialize:function(){
            _.bindAll(this,"render","addItem");
            this.counter=0;
            this.render();
        },
        render:function(){
            $(this.el).append("<button id='add'>Add list item</button>");
            $(this.el).append("<ul></ul>");
        },
        addItem:function(){
            this.counter++;
            $("ul",this.el).append("<li>Hello World"+this.counter+"</li>");
        }
    })
    var listView=new ListView();
})(jQuery)

 

posted on 2013-06-08 10:20  Ijavascript  阅读(215)  评论(0编辑  收藏  举报