1. #1
    Sencha User
    Join Date
    Jul 2013
    Posts
    7
    Vote Rating
    0
    swts is on a distinguished road

      0  

    Default Answered: Data not showing in tpl

    Answered: Data not showing in tpl


    Why in my View wasn't be able to show data in the label tpl, but the text fields showed? It's because whenever I tap, I should record too in my Controller? How I should do?

    Controller
    Code:
    Ext.define('MyApp.controller.User', {
        extend: 'Ext.app.Controller',
    
        config: {
            refs: {
                mainView: '#Main',
                userForm: '#UserForm',
                userList: '#UserList'
            },
    
            control: {
                "#UserList": {
                    itemtap: 'onListItemTap'
                },
                "[action=save]": {
                    tap: 'onSave'
                },
                "[action=delete]": {
                    tap: 'onDelete'
                }
            }
        },
    
        onListItemTap: function(dataview, index, target, record, e, eOpts) {
            var form = Ext.create("MyApp.view.MyFormPanel",
                {
                    title: record.data.firstName
                });
            this.getMainView().push(form);
            form.setRecord(record);
    
        },
    
        onSave: function(button, e, eOpts) {
            var me = this;
            var form = this.getUserForm();
            var record = form.getRecord();
            var values = form.getValues();
    
            record.set(values);
    
            if(record.isValid()){
                record.save( {
                    success: function()
                    {
                        me.getMainView().pop();
                        me.getUserList().deselectAll();
                    }
                });
            }
            else{
                Ext.Msg.Alert("Error", "erro!");
            }
        },
    
        onDelete: function(button, e, eOpts) {
            var me = this;
            var form = this.getUserForm();
            var record = form.getRecord();
    
            record.erase({
                success: function()
                {
                    record.stores[0].remove(record);
                    me.getMainView().pop();
                }
            });
        }
    
    });
    View
    Code:
    Ext.define('MyApp.view.MyFormPanel', {
        extend: 'Ext.form.Panel',
    
        config: {
            id: 'UserForm',
            items: [
                {
                    xtype: 'textfield',
                    label: 'Field',
                    name: 'firstName'
                },
                {
                    xtype: 'textfield',
                    label: 'Field',
                    name: 'lastName'
                },
                {
                    xtype: 'panel',
                    layout: {
                        type: 'hbox'
                    },
                    items: [
                        {
                            xtype: 'button',
                            action: 'save',
                            flex: 1,
                            text: 'save'
                        },
                        {
                            xtype: 'button',
                            action: 'delete',
                            flex: 1,
                            text: 'delete'
                        }
                    ]
                },
                {
                    xtype: 'label',
                    tpl: [
                        '{firstName} {lastName}'
                    ]
                }
            ]
        }
    
    });

  2. Ok, the problem is the panel that you are trying to "configure" using the tpl is an inner item of your "main" (form panel). It does not "inherit" the main record automatically.

    You need to set its data by code. Add this on your "onListItemTap" function just after you set the record:

    Code:
    var panel = form.down('panel');
    panel.setData(record.data);

  3. #2
    Sencha User Diego Garcia's Avatar
    Join Date
    Jan 2012
    Location
    San José, Costa Rica.
    Posts
    85
    Answers
    13
    Vote Rating
    7
    Diego Garcia is on a distinguished road

      0  

    Default


    Try removing the "[" and the "]". Configure your template as a simple string.


    http://docs.sencha.com/touch/2.2.1/#....Label-cfg-tpl
    We are a community, let's behave like that.

  4. #3
    Sencha User
    Join Date
    Jul 2013
    Posts
    7
    Vote Rating
    0
    swts is on a distinguished road

      0  

    Default


    Well, almost I got your answer right, but still one thing that I couldn't figured out:
    It's always showing firstName, because my data is "firstName : 'firstName'". How can I fix it?
    edit: even removing the data, still not showing the firstName and lastName.
    Code:
    Ext.define('MyApp.view.MyFormPanel', {
        extend: 'Ext.form.Panel',
    
        config: {
            id: 'UserForm',
            items: [
                {
                    xtype: 'textfield',
                    label: 'Field',
                    name: 'firstName'
                },
                {
                    xtype: 'textfield',
                    label: 'Field',
                    name: 'lastName'
                },
                {
                    xtype: 'panel',
                    data: {
                        firstName: 'firstName'
                    },
                    tpl: Ext.create('Ext.XTemplate', 
                        '{firstName} {lastName}',
                        {
                            disableFormats: true
                        }
                    ),
                    layout: {
                        type: 'hbox'
                    },
                    items: [
                        {
                            xtype: 'button',
                            action: 'save',
                            flex: 1,
                            text: 'save'
                        },
                        {
                            xtype: 'button',
                            action: 'delete',
                            flex: 1,
                            text: 'delete'
                        }
                    ]
                }
            ]
        }
    
    });

  5. #4
    Sencha User Diego Garcia's Avatar
    Join Date
    Jan 2012
    Location
    San José, Costa Rica.
    Posts
    85
    Answers
    13
    Vote Rating
    7
    Diego Garcia is on a distinguished road

      0  

    Default


    Ok, the problem is the panel that you are trying to "configure" using the tpl is an inner item of your "main" (form panel). It does not "inherit" the main record automatically.

    You need to set its data by code. Add this on your "onListItemTap" function just after you set the record:

    Code:
    var panel = form.down('panel');
    panel.setData(record.data);
    We are a community, let's behave like that.

Thread Participants: 1

Turkiyenin en sevilen filmlerinin yer aldigi xnxx internet sitemiz olan ve porn sex tarzi bir site olan mobil porno izle sitemiz gercekten dillere destan bir durumda herkesin sevdigi bir site olarak tarihe gececege benziyor. Sitenin en belirgin ozelliklerinden birisi de Turkiyede gercekten kaliteli ve muntazam, duzenli porno izle siteleri olmamasidir. Bu yuzden iste. Ayrica en net goruntu kalitesine sahip adresinde yayinlanmaktadir. Mesela diğer sitelerimizden bahsedecek olursak, en iyi hd porno video arşivine sahip bir siteyiz. "The Best anal porn videos and slut anus, big asses movies set..." hd porno faketaxi