سؤال

أنا جديد على إكستجس وأنا باستخدام إكستجس-4.1 في الوقت الراهن.لدي نموذج أساسي ، أحتاج إلى ملء البيانات عند تحميل الصفحة.ورل الخادم سيعود جسون.

[{"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);
});

وكنت قادرا على ملء نفس جسون إلى الشبكة.يمكنك الرجاء مساعدتي من خلال...حصلت على الكثير من الأمثلة على الشبكة وحاولت ولكن لا يزال هناك حظ.ما ورد أعلاه هو أيضا مقتطف رمز معدل حصلت عليه أثناء التصفح.

هل كانت مفيدة؟

المحلول

load() وظيفة غير متزامن.لذلك فعلت الشيء الصحيح-إنشاء معالج لحدث التحميل ووضع المنطق هناك.ومع ذلك فعلت أخطاء الزوجين:

  1. في معالج التحميل ، سيكون لديك بعض المعلمات للوظيفة.سيتم تخزين المعلمة الأولى - لذلك لا تحتاج إلى استخدام متغير عمومي.

  2. لا تحتاج إلى الحصول على this.testForm.getForm().loadRecord(app.formStore); - لأنه ليس أمرا صالحا وفي تلك اللحظة ليس لديك أي فكرة عما إذا كان متجرك محملا بالفعل أم لا.إزالته.لديك بالفعل سجلات التحميل في معالج المتجر.

  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) إذا كنت تبحث عن ملف UR على LocalHost، فلا تضع المحلي على عنوان URL فقط اكتب

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

ما هو ملف PHP الخاص بك؟هل يمكن نشر الرمز؟

3) ضع تكوين الوكيل على الطراز ليس في المتجر.

4) هل لديك محاولة اختبار إذا كان المتجر قد قرأ سجلات على الحمل؟مع console.log؟

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top