2

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: -------------------------------
4

2 回答 2

0

创建它的一个实例。当您创建实例时,actions哈希将移至_actions.

foo = App.ApplicationController.create();

foo._actions.pageBlock();

就我个人而言,我通常只是在应用程序模板上扔一个按钮

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

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

此外,您可以使用 Ember Inspector 在控制台中轻松获取控制器的实例,方法是在调试器工具的 Ember 选项卡中单击应用程序控制器的 $E。 https://chrome.google.com/webstore/detail/ember-inspector/bmdblncegkenkacieihfhpjfppoconhi?hl=en

于 2014-05-29T03:41:30.113 回答
0

我希望为此找到更好的答案,但这就是我的做法。首先,使用调试器输出找到您的应用程序视图 ID。然后您可以在 console.log 中运行以下命令:

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

我引用的帖子是Ember-JS-Best-Practices-helpful-debugging-tools

于 2014-05-29T05:00:10.840 回答