本文介绍了锤JS不与骨干工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图让与骨干工作锤子JS事件,但不能让它响应事件。
我试过下面已经..

I'm trying to get hammer js events working with backbone but can't get it to respond to events.I've tried the following already..

http://cijug.net/tech/2013/01/16/backbone-hammer/

我也把下面一片code在我看来

I've also put below piece of code in my view

initialize: function(){
    this.events = _.extend({}, this.defaultEvents, this.events||{});
}

JS小提琴:

code

<div id="swiping"></div>

JS

AppView = Backbone.View.extend({

  el: '#swiping',

  events: {
    'swipe': 'swipeMe'
  },

  render: function(){
    this.$el.html('<h2>Swipe Me</h2>');
  },

  swipeMe: function(e){
    alert('swiped ' + e.direction);
  }

});

var view = new AppView();
view.render();

包含的库 - hammer.js,jquery.specialevent.hammer.js等。

Libraries Included - hammer.js , jquery.specialevent.hammer.js , etc..

反正得到它的工作?

推荐答案

您不需要特殊事件插件,我只是去与jQuery插件,然后运行锤()在功能上渲染。

You don't need the special events plugin, I'd just go with the jquery plugin and then run the hammer() function in your render.

  render: function(){
    this.$el.html('<h2>Swipe Me</h2>');
    this.$el.hammer();
  },

下面是一个更新的提琴:

Here's an updated fiddle: http://jsfiddle.net/XcYhD/20/

这篇关于锤JS不与骨干工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-06 23:25