【问题标题】:Extjs 4 set combox values in form load eventExtjs 4 在表单加载事件中设置组合框值
【发布时间】:2012-03-07 18:28:28
【问题描述】:

我有一个包含 2 个组合框字段的表单,它们是链接的组合框字段。

章节和课程

当用户选择一章时,将显示该章的课程列表。

如何根据 EXTjs 4 中的章节组合过滤课程组合。如果选择章节组合,则只有课程组合应显示课程,否则应为空。

以及如何设置从服务器加载表单数据并填充到表单字段中时选择的 cmobo 值。

章节商店

var chapter_store = Ext.create('Ext.data.Store', {
    autoLoad: true,
    fields: ['chapter_id', 'chapter_name'],
    proxy: {
        type: 'ajax',
        url: BASE_URL + 'courses/chapters/getChaptersCombo/' + course_id,
        actionMethods: {
            read: 'POST'
        },
        noCache: false,
        reader: {
            type: 'json',
            root: 'results',
            totalProperty: 'total'
        }
    },
    storeId: 'chapter_id'
});

教具店

var lesson_store = Ext.create('Ext.data.Store', {
    autoLoad: true,
    fields: ['lesson_id',
             //'chapter_name',
             'lesson_name', 'lc_relation_id'
             ],
    proxy: {
        type: 'ajax',
        url: BASE_URL + 'courses/lessons/getLessonsCombo/' + course_id,
        actionMethods: {
            read: 'POST'
        },
        noCache: false,
        reader: {
            type: 'json',
            root: 'results',
            totalProperty: 'total'
        }
    },
    storeId: 'lesson_id'
});

带有链接组合的表单

 var quiz_form = Ext.create('Ext.form.Panel', {
    items: [{
        xtype: 'combobox',
        //readOnly:true,
        id: 'test_chapter_combo',
        name: 'test_chapter_combo',
        //hiddenName: 'test_linkchapter_val',
        displayField: 'chapter_name',
        valueField: 'chapter_id',
        fieldLabel: 'Select Chapter',
        allowBlank: false,
        blankText: 'Chapter is required',
        triggerAction: 'all',
        queryMode: 'remote',
        store: chapter_store,
        selectOnFocus: true,
        listeners: {
            select: {
                fn: function (combo, value) {
                    var comboLesson = Ext.getCmp('test_lesson_combo');
                    comboLesson.clearValue();
                    lesson_store.load({
                        params: {
                            chapters_id: combo.getValue()
                        }
                    });
                }
            }
        }
    }, {
        xtype: 'combobox',
        //readOnly:true,
        id: 'test_lesson_combo',
        name: 'test_lesson_combo',
        //hiddenName: 'test_linklesson_val',
        displayField: 'lesson_name',
        valueField: 'lc_relation_id',
        mode: 'local',
        fieldLabel: 'Link To Lesson',
        allowBlank: false,
        blankText: 'Lesson is required',
        triggerAction: 'all',
        store: edu_lesson_store,
        queryMode: 'remote'
    }]
});

从服务器加载表单数据

quiz_form.getForm().load({
    url: BASE_URL + 'courses/getCourseTest/' + quiz_id,
    method: 'POST'
});

【问题讨论】:

    标签: combobox extjs4 store


    【解决方案1】:

    我不知道您使用的是哪种服务器端技术,但我相信您可以通过以下 2 个很棒的链接获得一些灵感/指导:

    HTH!

    【讨论】:

    • 我正在使用 PHP - codeigniter 作为服务器端技术。现在过滤工作正常。当我从服务器加载表单数据(例如已保存表单的编辑模式)并使用远程存储时,如何在组合框中设置值。如果为组合框使用数组数据存储,则在从服务器加载表单数据时会自动将值选择到组合框中。
    • 尝试将组合配置中的name属性设置为“chapter_id”,然后尝试使用form.loadRecord(model_record),表单会将模型记录中的值绑定到具有name="model_field_name",更多关于 loadRecord() 的信息在这里docs.sencha.com/ext-js/4-0/#!/api/…
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-11-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-04-16
    相关资源
    最近更新 更多