Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ionic-framework/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ember.js 告诉组件通过父级重新加载自身_Ember.js - Fatal编程技术网

Ember.js 告诉组件通过父级重新加载自身

Ember.js 告诉组件通过父级重新加载自身,ember.js,Ember.js,我在屏幕上有各种余烬组件。组件使用gridster.js存储在网格中。在gridster中调整长方体大小时,可以使用“停止”功能在调整长方体大小时访问 export default Ember.View.extend(Ember.Evented,{ setupGridster : function() { $(".gridster ul").gridster({ widget_base_dimensions: [140, 140],

我在屏幕上有各种余烬组件。组件使用gridster.js存储在网格中。在gridster中调整长方体大小时,可以使用“停止”功能在调整长方体大小时访问

export default Ember.View.extend(Ember.Evented,{

    setupGridster : function() {
        $(".gridster ul").gridster({
            widget_base_dimensions: [140, 140],
            widget_margins: [5, 5],
            helper: 'clone',
            resize: {
                enabled: true,
                max_size: [4, 4],
                min_size: [1, 1],
                start: function(e, ui, $widget) {

                },

                resize: function(e, ui, $widget) {

                },

                stop: function(e, ui, $widget) {
                    self.trigger('widget:resize:stop');
                    console.log('widget:resize:stop');
                }
            }
        }).data('gridster');

    ...
在组件中,我有:

this.on('widget:resize:stop', this, 'rerender');
但是组件的作用域中似乎没有“widget:resize:stop”事件,因此代码永远不会执行

  • 如何让每个组件访问“widget:resize:stop”事件
  • 有更好的方法吗

  • 使用
    on()
    来“监听”事件时,需要获取触发该方法的对象的实例,并调用该对象上的
    on
    方法

    很难确切地知道您需要查找什么对象,因为我不知道您的组件/视图的树,但是如果前面提到的组件的父级是上面的
    Em.View
    代码,您应该听:

    this.get('parentView').on('widget:resize:stop', this, this.rerender);
    
    另外,请确保您正在使用willInsertElement或didinertelement等方法调用上的
    。例如:

    watchForResize: function() {
        this.get('parentView').on('widget:resize:stop', this, this.rerender);
    }.on('willInsertElement'),