小编cre*_*buh的帖子

keyup事件没有解雇 - 主干

我的一个Backbone.Marionette Views中的JQuery事件有问题.我已经定义了一些点击和键盘事件.但其中一些不起作用.例如,我希望每次触发keyup事件时都会调用fetch-function.

所以这是代码:

return Backbone.Marionette.ItemView.extend({
  tagName: 'div',
  template: Template,
  events:{
     'click .yes': 'yes',
     'click .no': 'no',
     'keyup #citySearch': 'fetch'
  },
  yes : function() {
    this.close();
  },
  no : function() {
    this.close();
  },
  initialize: function(){
    this.collection = new AreaCollection();
    this.collection.on('sync', this.onShow, this);
    this.sourceArr = [];
  },
  onShow: function() {
      var that = this;
      $('#citySearch').typeahead({
          source: that.sourceArr
      });
  },
  fetch: function(ev) {
    var that = this;
    that.collection.fetch({
      data : {
        query : $(ev.currentTarget).val(),
        type : 'cities'
      },
      success: function(response) {
        for (var …
Run Code Online (Sandbox Code Playgroud)

events bind backbone.js keyup marionette

5
推荐指数
1
解决办法
1万
查看次数

标签 统计

backbone.js ×1

bind ×1

events ×1

keyup ×1

marionette ×1