English 中文(简体)
Exjs combo盒,对阵列储存没有约束力
原标题:extjs combo box not binding to array store
  • 时间:2012-01-12 16:12:07
  •  标签:
  • extjs
  • extjs4

采用“外部设计者-供批-js-4-users-guide.pdf”这一范例,将以下各点结合起来。 问题是该仓库没有约束力。 因此,选择是空的。

MyComboBox.js

Ext.define( MyApp.view.MyComboBox , {
    extend:  MyApp.view.ui.MyComboBox ,

    initComponent: function() {
        var me = this;
        me.callParent(arguments);
    }
});

Ext.define( MyApp.view.ui.MyComboBox , {
    extend:  Ext.form.field.ComboBox ,

    fieldLabel:  comboList ,
    displayField:  comboList ,
    queryMode:  local ,
    store:  MyArrayStore ,
    triggerAction:  all ,
    valueField:  comboList ,

    initComponent: function() {
        var me = this;

        me.callParent(arguments);
    }
});

仓库/仓库。

  Ext.define( MyApp.store.MyArrayStore , {
    extend:  Ext.data.Store ,

    constructor: function(cfg) {
        var me = this;
        cfg = cfg || {};
        me.callParent([Ext.apply({
            autoLoad: true,
            storeId:  MyArrayStore ,
            data: [
                [
                     Search Engine 
                ],
                [
                     Online Ad 
                ],
                [
                     Facebook 
                ]
            ],
            proxy: {
                type:  ajax ,
                reader: {
                    type:  array 
                }
            },
            fields: [
                {
                    name:  comboList 
                }
            ]
        }, cfg)]);
    }
});

** 本文件迟交。

这使我.。 其<条码>[标题]***,我阵列必须采用json格式。 一经更新

[{"comboList" : "Hello"}, {"comboList" : "Hi"}, {"comboList" : "GoodMorning"}]

它发挥了作用。

最佳回答

我开始尝试并分散执行,但似乎有些混淆,从有当地数据的仓库开始。 a proxy界定但无ur。

简便地向您提供 com子(使用当地数据,因为你似乎正在做些什么):

// the datastore
var myStore = Ext.create( Ext.data.Store , {
    fields: [ value ,  name ],
    data: [
        {value: 1, name:  Search Engine },
        {value: 2, name:  Online Ad },
        {value: 3, name:  Facebook }
    ]
});    

// a window to hold the combobox inside of a form 
myWindow = Ext.create( Ext.Window , {
    title:  A Simple Window ,
    width: 300,
    constrain: true,
    modal: true,
    layout:  fit ,
    items: [{
        // the form to hold the combobox
        xtype:  form ,
        border: false,
        fieldDefaults: {
            labelWidth: 75
        },
        bodyPadding:  15 10 10 10 ,
        items: [{
            // the combobox
            xtype:  combo ,
            id:  myCombo ,
            fieldLabel:  Title ,
            valueField:  value ,
            displayField:  name ,
            store: myStore,
            queryMode:  local ,
            typeAhead: true,
            forceSelection: true,
            allowBlank: false,
            anchor:  100% 
        },{
            // shows the selected value when pressed
            xtype:  button ,
            margin:  10 0 0 100 ,
            text:  OK ,
            handler: function() {
                alert( Name:   + Ext.getCmp( myCombo ).getRawValue() + 
                       
Value:   + Ext.getCmp( myCombo ).value);
            }
        }]
    }]
});
// show the window
myWindow.show();   

This creates a combobox inside of a little window with an OK button. When you press OK it will alert the visible text of the combobox Ext.getCmp( myCombo ).getRawValue() and the value of the item in the combobox Ext.getCmp( myCombo ).value.

如果你在你的项目中放弃这一点,你就能够了解如何执行,那么它就应该走下去了。

如果你真的想要一个遥远的数据库(例如,从一个网络服务处回来)的话,那么你就只需改变数据储存配置。

var myRemoteStore = Ext.create( Ext.data.Store , {
    fields: [ value ,  name ],
    proxy: {
        type:  ajax , 
        url:  myWebservice.php , // whatever your webservice path is
        reader:  json ,
    },
    autoLoad:true  
});
问题回答

暂无回答




相关问题
ExtJS load form items/fields from database

I am using ExtJS 3 here. I would like to populate a formpanel from database with fields to be submitted. Basically, I don t know witch fields my form will have and I want to generate all formpanel ...

How to use Ext JS for role based application

I am planning to use Ext JS for a large application. The application s features are role based. When user login, they only see menu and screen features related to them. My server side technology will ...

Dynamically adding a TabPanel to a Panel Region

I have a Panel layout with a TreePanel in one region. A user clicks on an node in the tree and a TabPanel should be displayed in another region with information, editing tools etc. for that tree node....

How to embed Json result within Extjs Panel?

I have some issues with Json result and embed it within the html of the Extjs Panel. Here s that I have managed to get so far. myPanel is embedded within a mainPanel, and I have some shows/hide of ...

Ajax data update. Extjs

I need to keep certain data ( in a grid) up to date and was gonna do a poll to the server every 15 seocnds or so to get the data and refresh the grid, however it feels a bit dirty ( the grid will have ...

Better way to call superclass method in ExtJS

All the ExtJS documentation and examples I have read suggest calling superclass methods like this: MyApp.MyPanel = Ext.extend(Ext.Panel, { initComponent: function() { // do something MyPanel ...

Merged Headers in Ext JS Grid

Is it possible to have two headers in Ext JS grids? I have to show my grid as grouped data.. for example product types and products. In my case I need a grid like this: Field | Product Type A ...

热门标签