如何通过按下按钮 [javascript] [Gjs] 从 St.ScrollView 中删除演员并添加其他演员

how to remove an actor from a St.ScrollView and add other, by pressing a button [javascript] [Gjs]

我有以下代码:在 St.ScrollView 我添加了 St.BoxLayout 。 St.Scrollview 添加到 menu.box.Now 我想创建一个 St.Button,从 St.ScrollView 中删除 St.BoxLayout 并添加另一个 St.BoxLayout there.I 已尝试创建一个与按钮连接的函数 "clicked",并执行此操作:

    this.buttonnotifications.connect('clicked', this.displayNotifications);

    displayNotifications: function() {

      this.scrollbox.remove(this.vbox);
      this.menu.box.remove(this.scrollbox);
      this.scrollbox.add_actor(this.vbox1);
      this.menu.box.add(this.scrollbox);

},

但它没有 work.A 代码片段如下:

      this.buttonbox = new St.BoxLayout();
      this.buttontoday = new St.Button({ label: 'Today', width: 140, x_align: 1, style_class: 'selectbutton'});
      this.buttonnotifications = new St.Button({ label: 'Notifications', width: 140,  x_align: 1, style_class: 'selectbutton'});

      this.buttonbox.add_actor(this.buttontoday);
      this.buttonbox.add_actor(this.buttonnotifications);
      this.menu.box.add(this.buttonbox);

      this.scrollbox = new St.ScrollView({
                          height: 700,
                          width: 330,
                          hscrollbar_policy: 2,
                          vscrollbar_policy: 2,
                          enable_mouse_scrolling: true
                        });

      this.vbox = new St.BoxLayout({
                          //height: 1400,
                          //width: 330,
                          vertical: true,
                        //y_expand: true,
                          style_class: "datemenu-displays-box",
                          style: "border:10px;"
                        });

     this.vbox1 = new St.BoxLayout({
                          //height: 1400,
                          //width: 330,
                          vertical: true,
                        //y_expand: true,
                          style_class: "datemenu-displays-box",
                          style: "border:10px;"
                        });

      this.vbox.add_actor(this._date.actor);
      this.vbox.add_actor(this._calendar.actor);
      this.vbox1.add_actor(this._eventsSection.actor, {
                                               //x_fill: true
                                                 });
      this.vbox.add_actor(this._mediaSection.actor);
      this.vbox.add_actor(this._clocksSection.actor);
      this.vbox.add_actor(this._weatherSection.actor, {
                                                  //x_fill: true
                                                 });
      this.vbox1.add_actor(this._messageList.actor);

      this.scrollbox.add_actor(this.vbox);
      this.menu.box.add(this.scrollbox);     

换句话说,我想删除 vbox 并添加按下按钮通知的 vbox1。 任何帮助将不胜感激。 提前致谢。

我通过添加以下代码设法解决了这个问题:

this.buttonnotifications.connect('clicked', this.displayNotifications.bind(this));

与之前代码的区别是

 .bind(this)

方法。