Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/extjs/3.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
Javascript Ext Js Combobox-设置值的同步调用_Javascript_Extjs - Fatal编程技术网

Javascript Ext Js Combobox-设置值的同步调用

Javascript Ext Js Combobox-设置值的同步调用,javascript,extjs,Javascript,Extjs,我们不能用Ext.data.Store进行同步调用吗 我有一个模型,我正在商店里装。稍后我将它绑定到一个组合框。这个流程运行良好 但当我想为默认选择设置combo的值时,我会得到一个JS错误,说存储区中没有元素。原因是,填充存储的ajax调用是在执行所有JS之后进行的。我试着将async属性设置为false,但仍然没有成功 以下是我的代码片段: var store = new Ext.data.Store({ proxy: { type: 'ajax',

我们不能用Ext.data.Store进行同步调用吗

我有一个模型,我正在商店里装。稍后我将它绑定到一个组合框。这个流程运行良好

但当我想为默认选择设置combo的值时,我会得到一个JS错误,说存储区中没有元素。原因是,填充存储的ajax调用是在执行所有JS之后进行的。我试着将async属性设置为false,但仍然没有成功

以下是我的代码片段:

var store = new Ext.data.Store({        
    proxy: {
        type: 'ajax',
        url: '/GetAccounts',
        reader: {
            type: 'json'
        }
    },
    async: false,  //Tried this...no luck
    cache: false,
    autoLoad: true
});

var simpleCombo = Ext.create('Ext.form.field.ComboBox', {
    fieldLabel: 'For ',
    renderTo: 'simpleCombo',
    displayField: AccountName,
    valueField: 'AccountId',
    store: store,
    queryMode: 'local',
    forceSelection: true
});

simpleCombo.setValue(store.getAt(0).get('AccountId')); //JS ERROR AT THIS LINE. No elements in the store

禁用组合,直到填充存储。不要搞乱同步请求—您将冻结整个页面(甚至浏览器),直到请求完成。

我在上发布了类似的内容,但我采取了这种方法:

将侦听器添加到组合框中,以便在实际呈现组合框时,它应该尝试设置其值

侦听器:{
范围:本,,
afterRender:this.selectFirstComboItem
}
然后将该方法添加到您的
中(或您喜欢的任何地方)

selectFirstComboItem:函数(组合){
//这将告诉我们组合框是否至少加载过一次
if(typeof combo.getStore().lastOptions!=“未定义”){
//从存储中获取第一个值
setValue(combo.getStore().first().get(combo.valueField));
}
否则{
//商店装货时
combo.getStore().on(“加载”,函数(存储,项){
//抓取新加载数据的第一项
combo.setValue(项[0].get(combo.valueField));
});
}
}