1

How can i change a xtype in Sencha Architect?

Example:

from:

xtype: 'list'

to

xtype: 'RefreshableList'

MattioliSencha
  • 147
  • 1
  • 6

2 Answers2

6

As a disclaimer, I am one of the lead engineers on the Sencha Architect product.

Drag out a List as a top level component. All top level components are their own classes. Set the userAlias and userClassName configurations to values like 'refreshablelist' and 'RefreshableList'. Take a look at the code generated for this.

Drag out a Panel as a top level component, drag the existing RefreshableList in the inspector into the new Panel. A prompt will ask you if you would like to Move, Copy or Link the list, choose "Link". This will create an instance of your subclass RefreshableList.

This is currently the best way of going about this task inside of Architect. In the case that you built your RefreshableList component outside of Architect and would like to link it in the process will be a little different. You will have to create an override and change the xtype you are instantiating there. We are attempting to address this limitation in Sencha Architect 2.2. You will be able to specify what we are currently calling a createAlias. This is what alias (xtype, ptype, type, etc) to create.

For example if you dragged out a Panel and then put a list inside of it, you could then select the list in the inspector and configure the createAlias to 'RefreshableList'. This will replace the xtype in the generated code from 'list' to 'RefreshableList'. It will NOT change what is rendered on the canvas inside of Architect. You would have to load your RefreshableList class via a JS Resource and/or the dynamic loader/requires functionality.

Aaron Conran
  • 321
  • 1
  • 6
  • Thanks for this, @aaron-conran, but it assumes that the subclass is going to be of an item that is a controller, view, model or store. I'm currently dealing with a Sencha Architect project that needs to solve for http://www.sencha.com/forum/showthread.php?124362-Nested-loading-nested-saving-in-new-data-package#post_627595, and there's no way to subclass a JsonWriter in the manner you describe. Any thoughts? :) – Brian Topping Dec 17 '12 at 19:58
  • Add a file from Resources -> JS Resource. This is a raw JavaScript file that will be included after we load the library. It'd probably be easiest to just override JsonWriter completely. We have some features coming in Architect 2.2 which make this much easier. It's probably best to start your own thread in the Architect help forum and we can help you. – Aaron Conran Dec 19 '12 at 00:26
1

You have to create your own class by extending the list class and give it your own widget alias. This tutorial has all you need: http://www.sencha.com/learn/how-to-use-classes-in-sencha-touch-2/

UPDATE

Here is some code for a very basic custom list

//this follows the MVC structure, if you wanted you could also do something like ux.RefreshableList
Ext.define('myAppName.view.RefreshableList', {
    extend: 'Ext.dataview.List',
    xtype: 'RefreshableList',
    config: {
        fullscreen: true,
        itemTpl: '{title}',
        data: [
            { title: 'Item 1' },
            { title: 'Item 2' },
            { title: 'Item 3' },
            { title: 'Item 4' }
        ]
    },
    initialize: function() {
        this.callParent();
    }
});
Jeff Wooden
  • 5,339
  • 2
  • 19
  • 24