简体   繁体   中英

Simple console.log controller action method in Ember.js

In my application.js controller I have the following actions:

export default Ember.ObjectController.extend({
    //------------------------------------------------------------
    currentPathChanged: function () {
        window.scrollTo(0, 0);
    }.observes('currentPath'),
    //------------------------------------------------------------
    actions: {
        //------------------------------------------------------------
        pageBlock: function(desc_text){
            if(typeof desc_text === 'undefined'){
                desc_text='Processing';
            }
            $.blockUI.defaults.css = {};
            $.blockUI({message: desc_text});
        },
        pageUnBlock: function(){
            $.unblockUI({fadeOut:200});
        }
        //------------------------------------------------------------
    }
    //------------------------------------------------------------
});

Since I am rather new to debugging Emberjs applications, how do I call those actions from the console? Basically I want to confirm they work correctly and want to hook them up to child views.

I am using the ember cli project to build my ember application.

Current setup at the time of this post:

DEBUG: -------------------------------
DEBUG: Ember      : 1.5.1
DEBUG: Ember Data : 1.0.0-beta.7+canary.b45e23ba
DEBUG: Handlebars : 1.3.0
DEBUG: jQuery     : 2.1.1
DEBUG: -------------------------------

Create an instance of it. When you create an instance the actions hash is moved to _actions .

foo = App.ApplicationController.create();

foo._actions.pageBlock();

Personally I usually just throw a button on the application template

<button {{action 'pageBlock' foo}}>Block action</button>

http://emberjs.jsbin.com/lorocere/1/edit

Additionally you can use the Ember Inspector to get an instance of the controller in the console really easily by clicking on the $E for the application controller in the Ember tab in the debugger tools. https://chrome.google.com/webstore/detail/ember-inspector/bmdblncegkenkacieihfhpjfppoconhi?hl=en

I am hoping to find a better answer for this, but here is how I did it. First, using the debugger output find you application view id. Then you can run the following in the console.log:

foo = Ember.View.views['ember277'].get('controller');
foo._actions.pageBlock();
foo._actions.pageUnBlock();

The post I referenced was Ember-JS-Best-Practices-helpful-debugging-tools .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM