尝试为商店中的每个项目创建一个字段集

时间:2018-06-18 10:39:03

标签: extjs extjs6-modern

我对ExtJS非常陌生,并且非常迷失。我创建了一个数据存储 -

cursor = connection.cursor()
    SQLCommand = ("IF EXISTS(SELECT 1 FROM msdb.dbo.sysjobs J JOIN 
msdb.dbo.sysjobactivity A ON A.job_id = J.job_id WHERE J.name ='dbo.SPNAME' AND 
A.run_requested_date IS NOT NULL AND A.stop_execution_date IS NULL) select 'The job is 
running!' ELSE select 'The job is not running.'")
    cursor.execute(SQLCommand)
    results = cursor.fetchone()
    sresult= str(results)
    while "The job is not running" in sresult:
        time.sleep(1)
        cursor.execute(SQLCommand)
        results = cursor.fetchone()
        sresult= str(results)

我现在要做的是为每个部分创建一个面板,使用部分名称(一,二三)作为标题。

我尝试了几种方法,所有方法都是不成功的。我该如何解决这个问题?

编辑 - 我试过的一些例子

var sections = Ext.create('Ext.data.Store', {
    data: [
        {"section" : "One"},
        {"section" : "Two"},
        {"section" : "Three"}
    ]
});

2 个答案:

答案 0 :(得分:0)

Ext.define defines classes, but you want to create new instances of the panel class and add them to the component hierarchy.

So that's what you have to do (you can add them to any existing and already rendered container component):

var parentContainer = ... 
var sectionStore = Ext.getStore(sections);
var allRecords = sectionStore || sectionStore.data("section");

allRecords.each(function(record) {
    parentContainer.add({
        xtype: 'panel',
        title: record,
        text: record
    });
});

答案 1 :(得分:0)

As you are using Ext.define('Ext.panel.Panel', You just only define a panel. Instead of define you need to use Ext.create().

FIDDLE

CODE SNIPPET

Ext.application({
    name: 'Fiddle',

    launch: function () {
        var sections = Ext.create('Ext.data.Store', {
                data: [{
                    "section": "One"
                }, {
                    "section": "Two"
                }, {
                    "section": "Three"
                }]
            }),
            fieldSetItems = [];

        sections.each(rec => {
            fieldSetItems.push({
                xtype: 'fieldset',
                title: rec.get('section')
            });
        });

        Ext.create({
            xtype: 'panel',
            title: 'Create Items by store',
            items: fieldSetItems,
            renderTo: Ext.getBody()
        });
    }
});