0

我是 sencha touch 的新手,我在下面的代码中遇到错误是选项卡更改功能 errorUncaught TypeError: Object [object Object] has no method 'getValues'

                           var uswrfeild =  Ext.getCmp('User_details');
                                //var fieldset = Ext.create('FieldSet_PersonalSettings');
                                //var fieldset= this.tab;
                                var values = uswrfeild.getValues();
                                cart = Ext.create('Items');
                                //alert(values);
                                //cart.add({field1:'value1',field2:'value2'});
                                cart.add(values);
                                cart.sync();

下面的代码是字段集代码

                    {
                        xtype: 'container',
                        title: 'User',
                        id: 'User_details',
                        itemId: 'mycontainer3',
                        scrollable: 'vertical',
                        items: [
                            {
                                xtype: 'fieldset',
                                id: 'FieldSet_PersonalSettings',
                                itemId: 'myfieldset12',
                                margin: '2%',
                                title: 'User',
                                items: [
                                    {
                                        xtype: 'textfield',
                                        label: 'Name',
                                        name: 'name',
                                        maxLength: 31,
                                        placeHolder: 'given-name family-name'
                                    },
                                    {
                                        xtype: 'emailfield',
                                        label: 'Email',
                                        name: 'email',
                                        required: true,
                                        maxLength: 63,
                                        placeHolder: 'name@example.com'
                                    },
                                    {
                                        xtype: 'textfield',
                                        label: 'Street',
                                        name: 'street',
                                        required: true,
                                        placeHolder: 'streetname'
                                    },
                                    {
                                        xtype: 'textfield',
                                        label: 'House Number',
                                        required: true,
                                        placeHolder: '123'
                                    },
                                    {
                                        xtype: 'textfield',
                                        label: 'Zipcode',
                                        required: true,
                                        autoCapitalize: true,
                                        maxLength: 10,
                                        placeHolder: '1234AA'
                                    },
                                    {
                                        xtype: 'textfield',
                                        label: 'Country',
                                        required: true,
                                        placeHolder: 'NL'
                                    }
                                ]
                            },
                            {
                                xtype: 'fieldset',
                                margin: '2%',
                                title: 'Sharing information',
                                items: [
                                    {
                                        xtype: 'checkboxfield',
                                        label: 'Receive email',
                                        labelWidth: '75%',
                                        checked: true
                                    },
                                    {
                                        xtype: 'checkboxfield',
                                        height: 49,
                                        label: 'Upload statistics (anonymously)',
                                        labelWidth: '75%',
                                        checked: true
                                    }
                                ]
                            }

贝洛代码是模型

Ext.define('iFP.model.item', {
    extend: 'Ext.data.Model',

    config: {
        fields: [
            {
                name: 'name',
                type: 'string'
            },
            {
                name: 'email',
                type: 'string'
            },
            {
                name: 'street',
                type: 'string'
            },
            {
                name: 'hno',
                type: 'auto'
            },
            {
                name: 'zipcode',
                type: 'int'
            },
            {
                name: 'country',
                type: 'string'
            }
        ]
    }
});

下面的代码是商店

        Ext.define('iFP.store.userlocalsettings', {
    extend: 'Ext.data.Store',

    requires: [
        'iFP.model.item'
    ],

    config: {
        autoSync: false,
        model: 'iFP.model.item',
        storeId: 'usersettingslocalstore',
        proxy: {
            type: 'localstorage'
        }
    }
});

我的目标是将文本 feid 值存储在浏览器本地存储中。请帮我任何朋友。提前致谢。

4

2 回答 2

0

您应该首先为每个字段设置 id,例如这样

 {
      xtype: 'textfield',
      label: 'Name',
      name: 'name',
      maxLength: 31,
      placeHolder: 'given-name family-name',
      itemId: 'tfName'
 },

那么你可以在函数中的某个事件之后获取字段的值

var namefield = this.down('#tfName'); 
var namevalue = namefield.getValue();

...

然后您可以将该值添加到存储

var store = Ext.getStore('userlocalsettings');
store.add({name: namevalue});
store.sync();

希望这会有所帮助。

于 2013-02-07T17:57:44.040 回答
0

您应该为您的表单设置 ID。

config: {
        itemId: 'form1'
}

然后在您的控制器中添加对该 ID 的引用

refs: {
      myPanel: '#form1'
}

我看不到你的按钮监听器。假设监听器的名字是“onTapSave”那么你应该试试这个,

onTapSave: function(component,button, options){

    var uswrfeild = this.getMyPanel();
    var values = uswrfeild.getValues();
}
于 2013-05-17T06:51:09.137 回答