Ember add customEvents

问题描述 投票:0回答:1

我正在使用Ember 2.9,并希望使用“粘贴”事件。

如何在启动应用程序时将粘贴添加为customEvent:

这是我当前的app.js:

import Ember from 'ember';
import Resolver from './resolver';
import loadInitializers from 'ember-load-initializers';
import config from './config/environment';

let App;

Ember.MODEL_FACTORY_INJECTIONS = true;

App = Ember.Application.extend({
  modulePrefix: config.modulePrefix,
  podModulePrefix: config.podModulePrefix,
  Resolver
});

loadInitializers(App, config.modulePrefix);

export default App;
ember.js
1个回答
0
投票

我在https://github.com/bartocc/stackoverflow-2176861处安装了一个演示Ember.js 2.9应用程序,演示了下面的代码。

这里是一个示例app.js,用于配置Ember.js以侦听paste事件:

// /app/app.js
import Ember from 'ember';
import Resolver from './resolver';
import loadInitializers from 'ember-load-initializers';
import config from './config/environment';

let App;

Ember.MODEL_FACTORY_INJECTIONS = true;

App = Ember.Application.extend({
  modulePrefix: config.modulePrefix,
  podModulePrefix: config.podModulePrefix,
  Resolver,

  // This is how you make your ember app listen the paste event
  customEvents: {
    paste: 'paste'
  }
});

loadInitializers(App, config.modulePrefix);

export default App;

the Ember.js 2.9 API中查找更多信息。

然后,使任何组件通过以下方法监听paste事件:

import Ember from 'ember';

export default Ember.Component.extend({
  paste(event) {
    const text = event.originalEvent.clipboardData.getData('Text');
    alert(`you've just pasted the text '${text}'`);
  }
});
© www.soinside.com 2019 - 2024. All rights reserved.