Ext.TaskMgr.start({
interval: 1000, //runs every 1 sec
run: function() {
Ext.Ajax.request({
url: 'ajaxGetRecords.action',
params: '',
//success: function(form, action){
success: function(response , options ){
var arr = Ext.decode(response.responseText).root;
for(var i=0;i<arr.length;i++){
user = new Users({
userId: arr[i].userId,
userName: arr[i].userName
});
ds.insert(0,user);
}
}
});
以上是ajax从后台取数据的代码,目前我是放在一个按钮的click上,怎么让在进入页面马上就开始每隔1秒读一次?谢谢
我的意思是这段代码应该放在页面的什么位置。
[b]问题补充:[/b]
顺便问一下ds.remove()的参数是什么
user = new Users({
userId: arr[i].userId,
userName: arr[i].userName
});
ds.remove(user);//这个报错,好像是索引有问题
[b]问题补充:[/b]
getAt( Number index ) : Ext.data.Record
Get the Record at the specified index.
getById( String id ) : Ext.data.Record
Get the Record with the specified id.
query( String field, String/RegExp value, [Boolean anyMatch], [Boolean caseSensitive] ) : MixedCollection
Query the records by a specified property.
queryBy( Function fn, [Object scope] ) : MixedCollection
Query the cached records in this Store using a filtering function. The specified function will be called with each re...
根据某个函数,和你的值,找到这个record先,然后再remove
这里面的参数,比如ID,我去哪里找,是我的userId吗?
[b]问题补充:[/b]
我在ds.getById(userId)取不到值
首先,你的store的reader定义是什么?
我猜是 fields:['userId','userName'] 而你又没有把userId指定为record的id,所以自然getById是不行的.
那就得这样:
[code="java"]var searchUserId="1";
//findBy是找到第一个符合的,如果你有多个,就得用queryBy返回一个map
var index = store.findBy(function(record,id){
return record.get('userId')==searchUserId;
});
store.removeAt(index);
[/code]
要多看看store的api文档.全部过一遍的话一定会让你事半功倍的.
如果你的英语不是很好的话,去看看大漠翻译过的:
[url]
http://damoqiongqiu.iteye.com/blog/413120[/url]
Ext啊 有定时执行任务的类,Ext.util.TaskRunner看看api 就知道怎么设置了
另外位置 应该放到onload里面 那样加载完就能自动执行
javascript本身也有定时执行的函数setInterval,可以写到页面最后,确保都加载完后在执行
放在
[code="java"]Ext.onReady(function(){
//here
});[/code]
Ext.data.Store
remove( Ext.data.Record record ) : void
Remove a Record from the Store and fires the remove event.
[b]Parameters:[/b]
record : Ext.data.Record
The Ext.data.Record object to remove from the cache.
[b]Returns:[/b]
void
你new一个新的USER,而这个USER不在STORE中, remove的时候自然找不到啦.
你应该看下STORE的
getAt( Number index ) : Ext.data.Record
Get the Record at the specified index.
getById( String id ) : Ext.data.Record
Get the Record with the specified id.
query( String field, String/RegExp value, [Boolean anyMatch], [Boolean caseSensitive] ) : MixedCollection
Query the records by a specified property.
queryBy( Function fn, [Object scope] ) : MixedCollection
Query the cached records in this Store using a filtering function. The specified function will be called with each re...
根据某个函数,和你的值,找到这个record先,然后再remove
首先,你的store的reader定义是什么?
我猜是 fields:['userId','userName'] 而你又没有把userId指定为record的id,所以自然getById是不行的.
那就得这样:
[code="java"
]var searchUserId="1";
//findBy是找到第一个符合的,如果你有多个,就得用queryBy返回一个map
var index = store.findBy(function(record,id){
return record.get('userId')==searchUserId;
});
store.removeAt(index);
[/code]
要多看看store的api文档.全部过一遍的话一定会让你事半功倍的.
如果你的英语不是很好的话,去看看大漠翻译过的:
[url]
http://damoqiongqiu.iteye.com/blog/413120[/url]
-.-!! 似乎卡机了下..发了2次...而且标签也错位了...