Answer the question
In order to leave comments, you need to log in
How to access the Ember object, or how to save the object on ctrl+s?
Sobsno question describes the problem.
There is an event catcher, there are several tabs with object editors, in the handler you can find out which tab is active, in the tab there is information about the object (name, id, or something else, if desired) How to get an object from the click handler and save it?
document.body.addEventListener('keydown', function (e) {
if ((e.keyCode === 83) && (e.ctrlKey)) {
e.preventDefault();
App.Tabs.tabs("option", "active"); //узнаем активный в данный момент таб
console.log('ctrl + s');
}
});
Answer the question
In order to leave comments, you need to log in
The approach seems to be not very ember-way, you are almost isolated from the framework structure by the handler. You are not going to listen to the entire application, but only in some section.
You can do something like this in the view through the mixin:
App.SaveModelMixin = Ember.Mixin.create({
onGlobalKeyDown: function() {
Ember.$(document).on('keydown', {view: this}, this.globalKeyDown);
}.on('didInsertElement'),
offGlobalKeyDown: function () {
Ember.$(document).off('keydown', this.globalKeyDown);
}.on('willDestroyElement'),
globalKeyDown: function (e) {
if ((e.keyCode === 83) && (e.ctrlKey)) {
e.preventDefault();
App.Tabs.tabs("option", "active"); //узнаем активный в данный момент таб
console.log('ctrl + s');
// e.data.view - представление
// e.data.view.get('controller') - контроллер, можно слать экшены
// e.data.view.get('controller.model') - модель роута
}
}
});
On the stackoverflow, they advised such a weight github.com/satchmorun/ember-shortcuts, it seems to work.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question