开发者

backbone.js click and blur events

I'm having some trouble with blur and click events in backbone. I have a view (code below) that creates a little search entry div with a button. I pop open this div and put focus on the entry field. If someone clicks off (blur) I notify a parent view to close this one. If they click on the button I'll initiate a search.

The blur behavior works fine, however when I click on the button I also get a blur event and can't get the click event. Have I got this 开发者_运维问答structured right?

BTW, some other posts have suggested things like adding timers to the div in case its being closed before the click event fires. I can comment out the close completely and still only get the blur event. Do these only fire one at a time on some kind of first-com-first-served basis?

PB_SearchEntryView = Backbone.View.extend({
    template: _.template("<div id='searchEntry' class='searchEntry'><input id='part'></input><button id='findit'>Search</button></div>"),
    events: {
        "click button": "find",
        "blur #part": "close"
    },
    initialize: function(args) {
        this.dad = args.dad;
    },
    render: function(){
        $(this.el).html(this.template());
        return this;
    },
    close: function(event){ this.dad.close(); },
    find: function() {
        alert("Find!");
    }
});


I am not sure what the problem was, but here is the jsbin code.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜