Гость
Целевая тема:
Создать новую тему:
Автор:
Форумы / HTML, JavaScript, VBScript, CSS [игнор отключен] [закрыт для гостей] / extjs + form.Panel как работать со Store? / 2 сообщений из 2, страница 1 из 1
04.08.2014, 11:51
    #38711948
slaviq
Участник
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
extjs + form.Panel как работать со Store?
Как загружать данные в форму?
Имеется главная форма accordion, нужно чтобы во время раскрытия одного из уровней (одна из форм), загружались данные

Main.js:
Код: javascript
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
Ext.define('Calc.view.Main', {
     extend: 'Ext.panel.Panel'
	,alias:'widget.main'
	,requires:['Calc.view.MainModel','Calc.view.MainController']
	,controller:'main'
	,viewModel:{type:'main'	}
    ,layout: {type: 'hbox'}
    ,items: [{
		xtype: 'panel',
		region: 'center', 
		width: '100%',
		height: '100%',
		layout: 'accordion',
		items: [{
			xtype: 'dataform',
			title: '<center><b>Анкета</b></center>',
			listeners: {
                beforeExpand : function(form){
					var rec = Ext.StoreMgr.lookup("datastore").getAt(0);
                    form.loadRecord(rec);
                }
            }
		}
...........


DataForm.js
Код: javascript
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
31.
32.
33.
34.
35.
36.
37.
38.
39.
40.
41.
42.
43.
44.
45.
46.
47.
48.
49.
50.
51.
52.
53.
54.
55.
56.
57.
58.
59.
60.
61.
62.
63.
64.
65.
66.
67.
68.
69.
70.
71.
72.
73.
74.
75.
76.
77.
78.
var DtStore = Ext.create('Calc.store.dataStore');

Ext.define('Calc.view.DataForm', {
	 extend:'Ext.panel.Panel'
    ,alias:'widget.dataform'
    ,requires: ['Ext.form.field.Text']
	,id:'dataform'
    ,initComponent: function(){
        Ext.apply(this, {
            activeRecord: null,
            iconCls: 'icon-user',
            frame: true,
            defaultType: 'textfield',
            bodyPadding: 5,
            fieldDefaults: {
                anchor: '100%',
                labelAlign: 'right'
            },
            items: [{
		xtype: 'textfield',
		fieldLabel: 'Фамилия',
		labelAlign: 'left',
		cls: 'row-pnf-style',
		flex: 1,
		name:'l_lname'
	}],
            dockedItems: [{
                xtype: 'toolbar',
                dock: 'bottom',
                ui: 'footer',
                items: ['->', {
                    iconCls: 'icon-save',
                    itemId: 'save',
                    text: 'Save',
                    disabled: true,
                    scope: this,
                    handler: this.onSave
                }, {
                    iconCls: 'icon-reset',
                    text: 'Reset',
                    scope: this,
                    handler: this.onReset
                }]
            }]
        });
        this.callParent();
    },

    setActiveRecord: function(record){
		var record = DtStore.getAt(0);
        this.activeRecord = record;
        if (record) {
            this.down('#save').enable();
            this.getForm().loadRecord(record);
        } else {
            this.down('#save').disable();
            this.getForm().reset();
        }
    },

    onSave: function(){
        var active = this.activeRecord,
            form = this.getForm();

        if (!active) {
            return;
        }
        if (form.isValid()) {
            form.updateRecord(active);
            this.onReset();
        }
    },

    onReset: function(){
        this.setActiveRecord(null);
        this.getForm().reset();
    }
});


и есть модель и стор jsoon
dataModel.js
Код: javascript
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
Ext.define('Calc.model.dataModel', {
    extend: 'Ext.data.Model',
	idProperty: 'l_id', 
	fields: [
		{name: 'l_id', type: 'int'},
		{name: 'l_lname',	type: 'string'},
		{name: 'l_drog_dt',type: 'date'},
		{name: 'l_sex',	type: 'string'}
	]
});


dataStore.js
Код: javascript
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
Ext.define('Calc.store.dataStore',{
	 extend:'Ext.data.JsonStore'
	,model:'Calc.model.dataModel'
	,alias:'store.datastore'
	,id:'datastore'
	,autoLoad: false
    ,buffered: false
	,proxy: {
		 type: 'ajax'
		,api:{
			 read:'/resources/jsn_rdata.php?act=read'
			,update:'/resources/jsn_rdata.php?act=update'
		}
		,reader: {
			type: "json" //json
		}
		,writer: {
			type: "json" //json
			,writeAllFields:true
		}
	}
});


не получается загрузить данные в форму. Cannot read property 'getAt' of undefined
как вообще происходит загрузка данных в форму и последующее сохранение данных формы через json
Заранее спасибо!
...
Рейтинг: 0 / 0
05.08.2014, 10:29
    #38712771
slaviq
Участник
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
extjs + form.Panel как работать со Store?
Вобщем не знаю какаие еще варианты для работы формы со store, но заставил работать свой вариант:

Main.js:
Код: javascript
1.
2.
3.
4.
listeners: {
                beforeExpand : function(form){
                    form.setActiveRecord();
                }




DataForm.js
Код: javascript
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
31.
32.
33.
34.
35.
36.
extend:'Ext.panel.Panel'  -> а нужно -> extend:'Ext.form.Panel'
.....
    ,initComponent: function(){
        Ext.apply(this, {
            activeRecord: null,
			HistDtStore:Ext.create('Calc.store.dataStore'),  //добавил сюда store
...
    setActiveRecord: function(){
		var record = this.HistDtStore.getAt(0);
        this.activeRecord = record;
        if (record) {
            this.down('#save').enable();
            this.getForm().loadRecord(record);
        } else {
            this.down('#save').disable();
            this.getForm().reset();
        }
    },
...
    onSave: function(){
        var active = this.activeRecord,
            form = this.getForm();

        if (!active) {
            return;
        }
        if (form.isValid()) {
			var values = this.getValues();
            this.HistDtStore.getAt(0).set(values);
			this.HistDtStore.save();
            form.updateRecord(active);
            this.onReset();
        }else{
		  alert('Не все обязательные поля заполнено правильно!');
		}
    }



dataStore.js
Код: javascript
1.
extend:'Ext.data.JsonStore' -> а нужно -> extend:'Ext.data.Store'



Может кому то пригодится ...
...
Рейтинг: 0 / 0
Форумы / HTML, JavaScript, VBScript, CSS [игнор отключен] [закрыт для гостей] / extjs + form.Panel как работать со Store? / 2 сообщений из 2, страница 1 из 1
Найденые пользователи ...
Разблокировать пользователей ...
Читали форум (0):
Пользователи онлайн (0):
x
x
Закрыть


Просмотр
0 / 0
Close
Debug Console [Select Text]