문제

나는 새로운 EXTJS 및 사 EXTJS-4.1 니다.저는 기본적인 형태는 나는 필요를 채우는 데이터 페이지의 짐입니다.서버는 url 을 사용.

[{"countryid":1,"countrycode":"US","countryname":"United States"}]

나의 양식은 코드

Ext.require([
    'Ext.form.*'
    //'Ext.layout.container.Column',
    //'Ext.tab.Panel'
    //'*'
]);

Ext.onReady(function() {
    Ext.QuickTips.init();

    var bd = Ext.getBody();

    /*
     * ================  Simple form  =======================
     */
    bd.createChild({tag: 'h2', html: 'Form 1 - Very Simple'});

    var required = '<span style="color:red;font-weight:bold" data-qtip="Required">*</span>';

Ext.define('app.formStore', {
extend: 'Ext.data.Model',
fields: [
   {name: 'countryid'},
   {name: 'countrycode'},
   {name: 'countryname'}
]
});

var myStore = Ext.create('Ext.data.Store', {
model: 'app.formStore',
proxy: {
    type: 'ajax',
    url : 'http://localhost/milestone_1/web/app_dev.php/md/country/show/1',
    reader:{ 
        type:'json'                     
    }
},
autoLoad:true,
    listeners: {
        load: function() {
            var form = Ext.getCmp('formJobSummary'); 
            form.loadRecord(myStore.data.first());
        }
    }
});


var testForm = Ext.create('Ext.form.Panel', {
                    width: 500,
                    renderTo: Ext.getBody(),
                    title: 'Country Form',
                    waitMsgTarget: true,
                    fieldDefaults: {
                        labelAlign: 'right',
                        labelWidth: 85,
                        msgTarget: 'side'
                    },
                    items: [{
                        xtype: 'fieldset',
                        items: [{
                                xtype:'textfield',
                                fieldLabel: 'ID',
                                name: 'countryid'
                            }, {
                                xtype:'textfield',
                                fieldLabel: 'CODE',
                                name: 'countrycode'
                            }, {
                                xtype:'textfield',
                                fieldLabel: 'COUNTRY',
                                name: 'countryname'
                        }]
                    }]

            });


    this.testForm.getForm().loadRecord(app.formStore);
});

할 수 있었을 채우는 동일한 JSON 을니다.당신이 도와주세요 수 있습니다 저를 통해...나의 예에는 그물 시도했지만 여전히 행운입니다.주어진 이상은 또한 수정한 코드 조각을 내가 가지고 검색하는 동안.

도움이 되었습니까?

해결책

load() 기능이 비동기적으로 수행됩니다.그래서 당신이 옳은 일을 처리기 load 이벤트고 논리가 있다.그러나 당신 커플 실수:

  1. 부하 핸들러를 매개 변수하는 기능입니다.첫 번째 매개 변수점-그래서 당신은 당신을 사용할 필요가 없 글로벌 변수입니다.

  2. 당신이 할 필요가 없 this.testForm.getForm().loadRecord(app.formStore); -지 않기 때문에 유효한 명령과 그 순간에 당신을 아무 생각이 없지점은 실제로 로드되거나지 않습니다.제거합니다.당신은 이미 loadRecords 에 저장 처리기입니다.

  3. 형태로 렌더링하고 저장하는 자동 로드은 두 가지 다양한 이벤트와 당신을 제어 할 수 없이 그들의 타이밍.그래서 나는 사용하지 않도록하는 것이 좋습니다 autoLoad 에 대한 저장하고 수동으로 통화 store.load() 후에는 것을 알고 양식을 준비합니다.

다른 팁

var form = Ext.getCmp('formJobSummary');console.log(form)undefined를 리턴 할 것입니다.양식에 이름을 지정하고 이동합니다.또는 더 나은 아직 ...

// Ext.require([
// 'Ext.form.*'
//'Ext.layout.container.Column',
//'Ext.tab.Panel'
//'*'
// ]); // you dont need ext.require for ext integrated stuff

Ext.onReady(function () {
    Ext.QuickTips.init();

    //var bd = Ext.getBody(); 

    /*
     * ================  Simple form  =======================
     */
    //bd.createChild({
    //  tag: 'h2',
    //  html: 'Form 1 - Very Simple'
    //}); // over written by the form anyway

    // var required = '<span style="color:red;font-weight:bold" data-qtip="Required">*</span>'; // never used

    Ext.define('app.formStore', {
        extend: 'Ext.data.Model',
        fields: [{
            name: 'countryid'
        }, {
            name: 'countrycode'
        }, {
            name: 'countryname'
        }]
    });



    var testForm = Ext.create('Ext.form.Panel', {
        width: 500,
        renderTo: Ext.getBody(),
        name:'formJobSummary', //why your orignal bit wasn't working
        title: 'Country Form',
        waitMsgTarget: true,
        fieldDefaults: {
            labelAlign: 'right',
            labelWidth: 85,
            msgTarget: 'side'
        },
        items: [{
            xtype: 'fieldset',
            items: [{
                xtype: 'textfield',
                fieldLabel: 'ID',
                name: 'countryid'
            }, {
                xtype: 'textfield',
                fieldLabel: 'CODE',
                name: 'countrycode'
            }, {
                xtype: 'textfield',
                fieldLabel: 'COUNTRY',
                name: 'countryname'
            }]
        }]

    });

    var myStore = Ext.create('Ext.data.Store', {
        model: 'app.formStore',
        proxy: {
            type: 'ajax',
            url: 'http://localhost/milestone_1/web/app_dev.php/md/country/show/1',
            reader: {
                type: 'json'
            }
        },
        autoLoad: true,
        listeners: {
            load: function (store,record,e) {
                testForm.loadRecord(store.first());
            }
        }
    });


});
.

시도 할 사항이 거의 없습니다 :

1) localhost에서 UR 파일을 찾는 경우 URL에 localhost를 넣지 마십시오. 만 씁니다

URL : '/milestone_1/web/app_dev.php/md/country/show/1'

ur php 파일은 무엇입니까?코드를 게시 할 수 있습니까?

3) 상점에없는 모델에 프록시 구성을 놓습니다.

4) 상점이로드에 대한 레코드를 읽는 경우 테스트하려고 시도합니까?console.log와 함께?

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top