0

I have just started using Sencha Architect, and I have problems doing even the simplest of things. I'm trying to go to the next view, when a button is clicked. The code I have so far makes an alert when the button is clicked.

Ext.define('MyApp.view.Login', {
    extend: 'Ext.Container',

    config: {
        layout: {
            align: 'center',
            type: 'vbox'
        },
        items: [
            {
                xtype: 'fieldset',
                width: 500,
                title: 'Login',
                items: [
                    {
                        xtype: 'selectfield',
                        label: 'Vælg bil',
                        store: 'cars'
                    },
                    {
                        xtype: 'passwordfield',
                        label: 'Adgangskode'
                    },
                    {
                        xtype: 'checkboxfield',
                        label: 'Husk mig'
                    },
                    {
                        xtype: 'button',
                        handler: function(button, event) {
                            alert("foo");
                        },
                        text: 'Log ind'
                    }
                ]
            }
        ]
    }

});

What should go instead of the alert, to add a new view?

sha
  • 17,824
  • 5
  • 63
  • 98
danielsvane
  • 613
  • 3
  • 8
  • 18

1 Answers1

0

You can use this one to open up a view with id "sampleview":

if(Ext.getCmp('sampleview'))
{
    Ext.Viewport.setActiveItem(Ext.getCmp('sampleview'));
}
else 
{
    var sample = Ext.create('App.view.SampleView');
    Ext.Viewport.setActiveItem(sample);
}
mostar
  • 4,723
  • 2
  • 28
  • 45
  • I can't get this to work. I have given my container the id 'sampleview', but nothing happens when the event fires. Not even an error in the console. My project is at https://github.com/danielsvane/senchaviewtest. Could you maybe take a look? Thanks. – danielsvane May 02 '12 at 22:55
  • Nevermind, you were right, I was just not using it correctly. Why is it necessary to create the view on the event? Is there a way to create it before, and just use 'Ext.Viewport.setActiveItem(Ext.getCmp('sampleview'));'? – danielsvane May 03 '12 at 09:24
  • I checked your code but as I see you only used one line of the above code. You can simply write: `var sample = Ext.create('App.view.SampleView'); Ext.Viewport.setActiveItem(sample);` instead of: `Ext.Viewport.setActiveItem(Ext.getCmp('sampleview'));` I wrote the above if-condition just to avoid multiple creation of the view. – mostar May 03 '12 at 10:25
  • Yeah, I caught that when looking at the code again. I thought the else clause would just create an empty view. Can you recommend any resources for Sencha Architect? There doesn't seem to be much out there. Thanks for the help! – danielsvane May 03 '12 at 17:08
  • You're welcome! Actually it is a very new tool so it's not documented well yet. So you should make do with the existing documents on [http://docs.sencha.com] for now. – mostar May 04 '12 at 06:04