Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ajax/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
ExtJS3.4:从ajax响应设置组合存储_Ajax_Extjs_Combobox - Fatal编程技术网

ExtJS3.4:从ajax响应设置组合存储

ExtJS3.4:从ajax响应设置组合存储,ajax,extjs,combobox,Ajax,Extjs,Combobox,我有一个ExrJs套餐 new Ext.form.ComboBox({ //store : myStore, //displayField : 'code', //valueField : 'code', fieldLabel : 'Tour Code', id : 'idTourCode', //allowBlank : false, typeAhead : true,

我有一个ExrJs套餐

new Ext.form.ComboBox({
        //store : myStore,
        //displayField : 'code',
        //valueField : 'code',
        fieldLabel : 'Tour Code',
        id : 'idTourCode',
        //allowBlank : false,
        typeAhead : true,
        forceSelection : true,
        mode : 'local',
        triggerAction : 'all',
        selectOnFocus : true,
        editable : false,
        hidden : false,
        disabled : true,
        minChars : 1,
        hideLabel : true,
        style : 'marginleft:10px',
        width : 361,
        emptyText : 'Tour Code'
        //flex : 1
    });
我发送了一个Ajax请求并从postgresql数据库检索数据,并尝试将此响应设置为组合的存储,如下所示

var jsonData = Ext.util.JSON.decode(response.responseText);
                            console.log(jsonData);
                            if (jsonData.tourRef.length > 0) {
                                Ext.getCmp('idTourCode').bindStore(jsonData.tourRef);
                                Ext.getCmp('idTourCode').setRawValue(jsonData.tourRef.code);
                                Ext.getCmp('idTourCode').setHiddenValue(jsonData.tourRef.code);
                            }
我的回答是这样的

{'tourRef':[{ 'code' : '16/01/2014 17:31:03-ROUTE 5(COLOMBO 08,10)' } , { 'code' : '21/01/2014 10:27:54-ROUTE 5(COLOMBO 08,10)' }  ]}
现在这个组合有两行空行,firebug控制台显示Ext.getCmp('idTourCode').setHiddenValue(jsonData.tourRef.code)

我正在使用extjs3.4

我的代码有什么问题,我如何修复它

问候

Ext.Ajax.request({
                          method: 'GET',
                          loadMask: true,
                          scope: this,
                          url: "http://" + host + "/" + projectName + "/"
                                + "TourReference",
                          success: function (response, request) {
                            Ext.MessageBox.alert('success', response.responseText);
                            var jsonData = Ext.util.JSON.decode(response.responseText);
                            console.log(jsonData);
                            if (jsonData.tourRef.length > 0) {
                                Ext.getCmp('idTourCode').bindStore(jsonData.tourRef);
                                Ext.getCmp('idTourCode').setRawValue(jsonData.tourRef.code);
                                Ext.getCmp('idTourCode').setHiddenValue(jsonData.tourRef.code);
                            }
                            Ext.Msg.show({
                                  title: 'Success',
                                  msg: 'success',
                                  buttons: Ext.MessageBox.OK,
                                  icon: Ext.MessageBox.INFO
                            });

                          },
                          failure: function (response, request) {
                            Ext.MessageBox.alert('failure', response.responseText);
                            Ext.Msg.show({
                                  title: 'Error',
                                  msg: 'error',
                                  buttons: Ext.MessageBox.OK,
                                  icon: Ext.MessageBox.ERROR
                            });
                          },
                          params : {
                            dateFrom : Ext.getCmp('fromDateCombo').getValue(),
                            dateTo : Ext.getCmp('toDateCombo').getValue(),

                          }
                     });

下面的代码应该可以解决您的问题。对不起,我在评论中的英语很差

var host = '127.0.0.1',
    projectName = 'superTours';

new Ext.form.ComboBox({
    typeAhead : true,
    id: 'idTourCode', // this is VERY VERY bad. Try to don't use 'id' anywhere
    forceSelection : true,
    mode : 'local',
    triggerAction : 'all',
    selectOnFocus : true,
    editable : false,
    mode : 'local',
    triggerAction : 'all',
    disabled : true,
    hideLabel : true,
    style : 'marginleft: 10px;',
    width : 361,
    emptyText : 'Select a Tour Code',
    /* very important params below */
    valueField: 'code',
    displayField: 'code',
    store: {
        xtype: 'jsonstore',
        autoLoad: false, // I set this parameter to false to prevent automatical load data to store after combo render
        url: 'http://' + host + '/' + projectName + '/' + 'TourReference',
        root: 'tourRef',
        fields: [ 'code' ],
        listeners: {
            load: function(store, records, options) {
                console.log('Combo store: data loaded');
            },
            loadexception: function() {
                // error while loading data
                console.log(arguments);
            }
        }
    }
});
如我所见,您的组合必须被禁用。如果存储参数为“autoLoad:false”,则在您想要加载之前不会加载它

若要向脚本发送日期周期,应从日期字段中删除“更改”和“选择”侦听器,并添加“显示”按钮。此按钮将向服务器发送日期字段参数。将此代码添加到按钮的处理程序:

handler:function(Btn) {
    var datefrom = Ext.getCmp('fromDateCombo').getValue(),
        dateto = Ext.getCmp('toDateCombo').getValue();
    Ext.getCmp('idTourCode').enable();
    Ext.getCmp('idTourCode').getStore().reload({
        params: {
            dateFrom: datefrom,
            dateTo: dateto
        }
    });
}

你的组合没有储存。这是个问题。您不应该使用ajax请求来填充组合列表,您应该存储!问题是,当用户在数据字段中选择日期时,存储ajax请求应该发送。我应该如何将其应用到日期字段的侦听器中?是的。使用我的代码进行组合,并在需要时加载要存储的数据。别忘了设置组合启用。如果使用“datefield”,则可以将此存储加载代码添加到“select”和“change”侦听器。它不使用dateFrom和dateTo值BaseParams或params?