combobox不能在extjs 4 mvc环境中运行?

时间:2012-04-15 09:28:48

标签: extjs sencha-touch extjs4 sencha-touch-2

我正在尝试运行组合框,但是当我将其添加到表单时,表单不会显示。

以下是表单的代码:

    Ext.define("Screener.view.Pharmacyform", {

          xtype: 'pharmacyform',
    extend: 'Ext.form.Panel',
    requires: ['Ext.tab.Panel','Ext.form.FieldSet'],

    config:{
         styleHtmlContent: true,
            xtype:'orderform',
            autoscroll: true,


          items:[{
                  xtype: 'fieldset',
                  title: 'Pharmacy Order',

         items: [
            {
                xtype: 'textfield',
                name : 'name',
                label: 'Name'
            },{
                {xtype: 'combo',
    fieldLabel: 'Combobox',
    name:'drugdrug',
    id:'combodrug',

    store: Ext.create('Screener.store.Drugs',{
                            storeId: 'drugstore'

                        }),
                        displayField: 'drugname',
                        valueField: 'drugname',
                        queryMode: 'local',
                        triggerAction: 'all'

        }


              ]
    }]

    }

    });

药店代码:

/*
 * This store loads the drugs from file 'drugs.json'
 * Note: there is no writer attached, so changes will
 * only occur in local cache
 */

    Ext.define('Screener.store.Drugs', {
        extend: 'Ext.data.Store',
    storeId: 'drugStore',

        config: {
            model: 'Screener.model.Drug',
            proxy: {
                type: 'ajax',
                url : 'drugs.json',
                reader: 'json',     
                },
            autoLoad: true

        }
    });

我是extjs的新手,请告诉我如何让它工作

3 个答案:

答案 0 :(得分:0)

你没有指定那么多。为了能够帮助你,我需要一个工作样本和你正在使用的sencha版本。

我在肤浅的观点中看到的是你有两个商店:第一个商店在组合框定义中定义为“内联”。该商店不是Ext.store.Store的后代,所以它不起作用。

第二个看起来几乎是正确的但是没有使用它,因为你要实例化第一个。

尝试在视图中将商店的定义更改为:

...
 fieldLabel: 'Combobox',
    name:'drugdrug',
    id:'combodrug',

    store: 'drugStore'
...

此外,您并未说明您是否在控制台中收到错误。

答案 1 :(得分:0)

问题是您是按名称引用存储,并且需要在加载视图之前加载该存储。您有三种选择:

在此视图的控制器中引用存储(.stores []),并在视图之前加载控制器

在application.stores []

中引用商店

按引用而不是按名称设置商店,例如:

{
xtype:'combobox',
store: new Ext.data.Store({model:'somemodel'}),
...
}

最后一个选项可能更好,因为组合通常可以更好地与自己的商店一起使用。例如,4.1RC2中存在一个错误,您无法在共享存储中使用分页。在这种情况下,请确保将代理放在模型上,以便在具有相同模型的商店之间不存在代码重复。

答案 2 :(得分:0)

嘿,你应该添加一个陈述

renderTo:Ext.getBody()