You found a bug! We've classified it as EXTJS-5480 . We encourage you to continue the discussion and to find an acceptable workaround while we work on a permanent fix.
  1. #1
    Sencha Premium Member karlsnyder0's Avatar
    Join Date
    Mar 2010
    Location
    Maryland, USA
    Posts
    82
    Vote Rating
    12
    karlsnyder0 is on a distinguished road

      0  

    Default [4.1 b3] TreeStore doesn't copy all standard Tree field's.

    [4.1 b3] TreeStore doesn't copy all standard Tree field's.


    I've found a bug when using a TreePanel with additional fields where the standard Tree field "text" isn't copied over into the Model.

    Code:
    new Ext.tree.TreePanel({
                flex: 1,
                style: 'padding-left: 5px;',
                useArrows: true,
                //border: false,
                rootVisible: false,
                autoScroll: true,
                
                root: { // NodeInterface
                    text: "All", 
                    expanded: true
                },
                
                fields: [{
                    name: 'myCustomField',
                    type: 'string'
                }]
    });
    * According to the Ext.data.TreeStore documentation:

    Using Models

    If no Model is specified, an implicit model will be created that implements Ext.data.NodeInterface. The standard Tree fields will also be copied onto the Model for maintaining their state. These fields are listed in the Ext.data.NodeInterface documentation.

    * According to the Ext.data.NodeInterface documentation:

    This class is used as a set of methods that are applied to the prototype of a Model to decorate it with a Node API. This means that models used in conjunction with a tree will have all of the tree related methods available on the model. In general this class will not be used directly by the developer. This class also creates extra fields on the model if they do not exist, to help maintain the tree state and UI. These fields are documented as config options.

    * The text field is documented as a config option:

    Config options
    ...
    text : String
    The text for to show on node label.

    The text field however is clearly missing when I try to do anything with the node. After inspecting the source the "text" field is missing from the NodeInterface source code:


    Code:
            decorate: function(modelClass) {            var idName, idType;
                if (typeof modelClass == 'string') {
                    modelClass = Ext.ModelManager.getModel(modelClass);
                }
                if (modelClass.prototype.isNode) {
                    return;
                }
                idName = modelClass.prototype.idProperty;
                idType = modelClass.prototype.fields.get(idName).type.type;
                modelClass.override(this.getPrototypeBody());
                this.applyFields(modelClass, [
                    {name: 'parentId',   type: idType,    defaultValue: null},
                    {name: 'index',      type: 'int',     defaultValue: null, persist: false},
                    {name: 'depth',      type: 'int',     defaultValue: 0, persist: false},
                    {name: 'expanded',   type: 'bool',    defaultValue: false, persist: false},
                    {name: 'expandable', type: 'bool',    defaultValue: true, persist: false},
                    {name: 'checked',    type: 'auto',    defaultValue: null, persist: false},
                    {name: 'leaf',       type: 'bool',    defaultValue: false},
                    {name: 'cls',        type: 'string',  defaultValue: null, persist: false},
                    {name: 'iconCls',    type: 'string',  defaultValue: null, persist: false},
                    {name: 'icon',       type: 'string',  defaultValue: null, persist: false},
                    {name: 'root',       type: 'boolean', defaultValue: false, persist: false},
                    {name: 'isLast',     type: 'boolean', defaultValue: false, persist: false},
                    {name: 'isFirst',    type: 'boolean', defaultValue: false, persist: false},
                    {name: 'allowDrop',  type: 'boolean', defaultValue: true, persist: false},
                    {name: 'allowDrag',  type: 'boolean', defaultValue: true, persist: false},
                    {name: 'loaded',     type: 'boolean', defaultValue: false, persist: false},
                    {name: 'loading',    type: 'boolean', defaultValue: false, persist: false},
                    {name: 'href',       type: 'string',  defaultValue: null, persist: false},
                    {name: 'hrefTarget', type: 'string',  defaultValue: null, persist: false},
                    {name: 'qtip',       type: 'string',  defaultValue: null, persist: false},
                    {name: 'qtitle',     type: 'string',  defaultValue: null, persist: false},
                    {name: 'children',   type: 'auto',   defaultValue: null, persist: false}
                ]);
            },
    I've followed the documentation so either there is a bug in the source of ExtJS 4.1 Beta 3 or there is a mistake in the in the documentation.

    If I follow the documentation then the solution is to "hack" the "text" field into the fields array. Is this a bug?
    Last edited by karlsnyder0; 27 Feb 2012 at 9:20 AM. Reason: comments between documentation pasting stand out

  2. #2
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    36,649
    Vote Rating
    817
    mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute

      0  

    Default


    I would think you should at least have the text field specified but we will get this fixed.
    Mitchell Simoens @SenchaMitch
    Sencha Inc, Senior Forum Manager
    ________________
    Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
    https://github.com/mitchellsimoens

    Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/

    Need more help with your app? Hire Sencha Services services@sencha.com

    Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is in print!

    When posting code, please use BBCode's CODE tags.

  3. #3
    Sencha User
    Join Date
    May 2009
    Posts
    135
    Vote Rating
    1
    DiscoBoy is on a distinguished road

      0  

    Default


    I noticed this behaviour only yesterday (NodeInterface gets applied to prototype of my model). My question is how to get my original model fields back? I also use my model in other parts of my app, e.g. in a PropertyGrid which is now populated by unwanted fields!

  4. #4
    Sencha Premium Member karlsnyder0's Avatar
    Join Date
    Mar 2010
    Location
    Maryland, USA
    Posts
    82
    Vote Rating
    12
    karlsnyder0 is on a distinguished road

      0  

    Default


    It took me a while to figure out but the workaround I used was to specify the following in the fields array property (seen above):

    Code:
    { name: 'text', type: 'string' }
    Does this help you DiscoBoy?

  5. #5
    Sencha User
    Join Date
    May 2009
    Posts
    135
    Vote Rating
    1
    DiscoBoy is on a distinguished road

      0  

    Default


    Thx for your suggestion. I currently just remove all "persitent=false" fields from my object copy that is configured as source in my PropertyGrid. This avoidsappearing the NodeInterface attributes in my grid.

Thread Participants: 2