How to update Extjs Progress Bar with JSON results?

时光毁灭记忆、已成空白 提交于 2019-12-21 05:38:10

问题


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.

I am able to create a json result like this:

{"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.

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. How do I update the progress bar with the given Json result?

Thank you very much.


回答1:


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.

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:


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?

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.

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.

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?

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.

// 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);


来源:https://stackoverflow.com/questions/1746579/how-to-update-extjs-progress-bar-with-json-results

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!