как удалить актера из St.ScrollView и добавить другого, нажав кнопку [javascript] [Gjs]

У меня есть следующий код: в St.ScrollView я добавил St.BoxLayout. St.Scrollview добавлен в menu.box. Теперь я хочу создать St.Button, чтобы удалить St.BoxLayout из St.ScrollView и добавить туда еще один St.BoxLayout. Я попытался заставить функцию «щелкнуть» связан с кнопкой, и сделайте это:

    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);

},

но это не работает. Ниже приведен фрагмент кода:

      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, нажав кнопку уведомления. Любая помощь будет оценена по достоинству. Заранее спасибо.


person cgiannakidis    schedule 29.11.2018    source источник


Ответы (1)


Мне удалось решить эту проблему, добавив этот код:

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

Отличие от предыдущего кода:

 .bind(this)

метод.

person cgiannakidis    schedule 01.12.2018