2016-05-30 3 views
0

У меня странная проблема. У меня был простой вид, который хорошо показывался, как только я пытаюсь добавить кнопку и пытаюсь открыть мое веб-приложение, ничего не отображается, вот соответствующий код, кто-нибудь может понять, что с ним не так?Не удается добавить кнопку на панель extJS

/** 
* This class is the main view for the application. It is specified in app.js as the 
* "autoCreateViewport" property. That setting automatically applies the "viewport" 
* plugin to promote that instance of this class to the body element. 
* 
* TODO - Replace this content of this view to suite the needs of your application. 
*/ 
Ext.define('Myapp.view.main.Main', { 
    extend: 'Ext.container.Container', 
    requires: [ 
     'Myapp.view.main.MainController', 
     'Myapp.view.main.MainModel' 
    ], 

    xtype: 'app-main', 

    controller: 'main', 


    items: [ 
     { 
      xtype: 'panel', 
      title: 'Child Panel 1', 
      height: 100, 
      columnWidth: 0.5, 
      items: [ 
      { 
       xtype: 'button', 
       text: 'Create', 
       itemId: 'createStudentID', 
       handler: onClickButton 
      }] 

     }, 
     { 
      xtype: 'panel', 
      title: 'Child Panel 2', 
      height: 100, 
      columnWidth: 0.5 
     } 
    ] 
}); 

Контроллер:

/** 
* This class is the main view for the application. It is specified in app.js as the 
* "autoCreateViewport" property. That setting automatically applies the "viewport" 
* plugin to promote that instance of this class to the body element. 
* 
* TODO - Replace this content of this view to suite the needs of your application. 
*/ 
Ext.define('Myapp.view.main.MainController', { 
    extend: 'Ext.app.ViewController', 

    requires: [ 
     'Ext.window.MessageBox' 
    ], 

    alias: 'controller.main', 

    onClickButton: function() { 
     Ext.define('Student', 
     { 
      name: 'unnamed', 

      getName: function() { 
       return "Student name is" + this.name; 
      } 
     }); 

     var studentObj = Ext.create('Student'); 
     studentObj.getName(); 
    } 


}); 

Я действительно запутался. Если удалить кнопку и ее обработчик я могу видеть, как мои две панелей

ответ

0

решен путем изменений обработчика слушатель

items: [ 
     { 
      xtype: 'panel', 
      title: 'Child Panel 1', 
      height: 100, 
      columnWidth: 0.5, 
      items: [ 
      { 
       xtype: 'button', 
       text: 'Create', 
       itemId: 'createStudentID', 
       listeners: { 
        click: 'onClickButton' 
       } 
      }] 

     }, 
0

Вы должны открыть консоль браузера, который расскажет вам, что

onClickButton is undefined 

Такой сообщение об ошибке было бы полезно читателю ... или вам.

+0

Консоль не сказала этого. проверить мой ответ –

+1

Он почти наверняка сказал бы, что если бы это был код, который у вас был в вашем OP. –

+0

@Evan Trimboli: он сказал что-то другое, я дважды проверю завтра, мой ответ решил это –

Смежные вопросы