如何使用JSON结果更新Extjs Progress Bar?

时间:2022-09-15 11:58:18

I am facing some difficulties in getting my progress bar to retrieve its progress from Json results and update the progress bar based on the timer check of every 10 seconds.

我在获取进度条以从Json结果中检索其进度并根据每10秒的计时器检查更新进度条时遇到一些困难。

I am able to create a json result like this:

我能够像这样创建一个json结果:

{"success":true, "progress":0.2}

I suppose the general idea is that, I need a task with interval set to 10sec, and having the runner to run the task, and when the progress bar starts working, the runner will check on the results from the Json, and update the progress bar as per required.

我想一般的想法是,我需要一个间隔设置为10秒的任务,让跑步者运行任务,当进度条开始工作时,跑步者将检查Json的结果,并更新进度根据要求吧。

Code so far:

代码到目前为止:

var task = {
    run: function(){
        // what to add here?
    },
        interval: 10000
    }
}

Having said so, I am having difficulties on:

话虽如此,我遇到了困难:

  1. How do I add the Json portion in the task?
  2. 如何在任务中添加Json部分?
  3. How do I update the progress bar with the given Json result?
  4. 如何使用给定的Json结果更新进度条?

Thank you very much.

非常感谢你。

2 个解决方案

#1


5  

I have managed to get this up and running, apparently this is the missing jigsaw to my question. For anyone who are stuck with this like me.

我已经设法让它运行起来,显然这是我的问题中缺少的拼图。对于像我这样坚持这个的人。

Basically just add this portion which will retrieve the json result from your stated url, and on success update your progress bar.

基本上只需添加此部分即可从您声明的网址中检索json结果,并在成功时更新您的进度条。

And the bare minimum code to be embedded within your task like so:

最简单的代码嵌入你的任务中,如下所示:

Ext.Ajax.request({
           url: 'getStatus',
           success: function(r) {
                 var i = Ext.decode(r.responseText).progress;
                 progressbar.updateProgress(count +' completed');
           }
});

#2


0  

I don't know what stack you are running on but what you can do in term of general approach.

我不知道你在运行什么堆栈但是你可以用一般方法做什么。


How do I add the Json portion in the task?

如何在任务中添加Json部分?

If you have access to memcached or something like that you can use that to store your progress of the task. On the same fashion you can use a database or even file, since what do you want to store is only a number.

如果您可以访问memcached或类似的内容,则可以使用它来存储任务的进度。以同样的方式,您可以使用数据库甚至文件,因为您要存储的只是一个数字。

After how to give a progress number of various task that you don't know how much time it would take. I would say if your processing is loop based like you update n rows, you can just use that as a meter.

如何给出各种任务的进度数,你不知道需要花多少时间。我会说如果您的处理是基于循环的,就像您更新n行,您可以将其用作仪表。

I think you don't have to worry the progress meter to be accurate just it should give a rough idea where the processing is.

我认为你不必担心进度表是准确的,只是它应该大致了解处理的位置。


How do I update the progress bar with the given Json result?

如何使用给定的Json结果更新进度条?

ExtJS have a TaskManager it would allow you to do an ajax query every n second and pull out the progress and update the attached progress bar.

ExtJS有一个TaskManager,它允许你每n秒进行一次ajax查询,并取出进度并更新附加的进度条。

// Start a simple clock task that updates a div once per second
var task = {
    run: function(){
        Ext.fly('clock').update(new Date().format('g:i:s A'));
    },
    interval: 1000 //1 second
}
Ext.TaskMgr.start(task);

#1


5  

I have managed to get this up and running, apparently this is the missing jigsaw to my question. For anyone who are stuck with this like me.

我已经设法让它运行起来,显然这是我的问题中缺少的拼图。对于像我这样坚持这个的人。

Basically just add this portion which will retrieve the json result from your stated url, and on success update your progress bar.

基本上只需添加此部分即可从您声明的网址中检索json结果,并在成功时更新您的进度条。

And the bare minimum code to be embedded within your task like so:

最简单的代码嵌入你的任务中,如下所示:

Ext.Ajax.request({
           url: 'getStatus',
           success: function(r) {
                 var i = Ext.decode(r.responseText).progress;
                 progressbar.updateProgress(count +' completed');
           }
});

#2


0  

I don't know what stack you are running on but what you can do in term of general approach.

我不知道你在运行什么堆栈但是你可以用一般方法做什么。


How do I add the Json portion in the task?

如何在任务中添加Json部分?

If you have access to memcached or something like that you can use that to store your progress of the task. On the same fashion you can use a database or even file, since what do you want to store is only a number.

如果您可以访问memcached或类似的内容,则可以使用它来存储任务的进度。以同样的方式,您可以使用数据库甚至文件,因为您要存储的只是一个数字。

After how to give a progress number of various task that you don't know how much time it would take. I would say if your processing is loop based like you update n rows, you can just use that as a meter.

如何给出各种任务的进度数,你不知道需要花多少时间。我会说如果您的处理是基于循环的,就像您更新n行,您可以将其用作仪表。

I think you don't have to worry the progress meter to be accurate just it should give a rough idea where the processing is.

我认为你不必担心进度表是准确的,只是它应该大致了解处理的位置。


How do I update the progress bar with the given Json result?

如何使用给定的Json结果更新进度条?

ExtJS have a TaskManager it would allow you to do an ajax query every n second and pull out the progress and update the attached progress bar.

ExtJS有一个TaskManager,它允许你每n秒进行一次ajax查询,并取出进度并更新附加的进度条。

// Start a simple clock task that updates a div once per second
var task = {
    run: function(){
        Ext.fly('clock').update(new Date().format('g:i:s A'));
    },
    interval: 1000 //1 second
}
Ext.TaskMgr.start(task);