gpt4 book ai didi

javascript - ExtJs 监听器

转载 作者:行者123 更新时间:2023-12-03 16:45:21 29 4
gpt4 key购买 nike

我想在我的配置对象上获得一个 onload 事件。

以下工作,除非我创建一个

config.listeners={..}

(我认为这就是我需要的?)替换
this.onload({...});

我什至使用正确的配置吗? (我一般对事件处理一无所知)
Ext.define('data.SimpleStore', {
extend: 'Ext.data.Store'
,constructor: function (config) {

config.url=config.url||"afsud"; //If no call, we assume that url has been passed. Pass neither and be shot
config.id=config.url+'Store';//call should be unique, else its another set of headaches.
//console.log(config);
Ext.define(config.id+'M', { //for a painful reason, you cant have a store without a model
extend: 'Ext.data.Model',
fields: []//we figure these out anyways
});
config.root=config.root||'data';
config.type=config.type||'json';
config.proxy= config.proxy||{ //note if we override our proxy, then server.php might not work as black magic
type: 'ajax'
,url : config.url
,reader: {
type: config.type//seriously if you want to change this, go away
,root: config.root//we assume.
}
};
config.model=config.id+'M';//model should match store anyway. Generic models are out of scope atm
config.listeners={
//this.populateFields //Error'd
};
this.callParent([config]);
this.load({//This works, but its after the parent call, so not exactly what i want
callback: function(records,operation,success){
var obj=Ext.decode(operation.response.responseText);
this.add(obj[config.root]);
console.log(this.getRange());
console.log(config);
}
});
}
,populateFields:function(){
console.log('ran'); // never happens
}
});

var s= Ext.create('data.Store',{url:'test.php'});
s.load();

最佳答案

在 ExtJS 中,事件是通过两种方式管理的:

首先,您可以在配置中添加 listeners 目的:

var s = Ext.create('data.SimpleStore',{
url:'test.php',
listeners: {
'load': function(store, records, successful,operation, options) {
//Here you are handling onload event
}
} //Don't forget to close all code blocks
});
s.load();

其次,您可以使用 on 方法:
var s = Ext.create('data.SimpleStore',{url:'test.php'});
s.on('load', function(store, records, successful,operation, options) {
//Here you are handling onload event
});
s.load();

关于javascript - ExtJs 监听器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6816185/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com