weixin_42333463 2009-08-14 17:15
浏览 270
已采纳

关于AJAX

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)取不到值

  • 写回答

7条回答 默认 最新

  • iteye_10013 2009-08-15 21:24
    关注

    首先,你的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]

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(6条)

报告相同问题?

悬赏问题

  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3
  • ¥15 牛顿斯科特系数表表示