Ext.js - 進度條



此類元件用於顯示已完成工作的進度,表示後臺工作仍在進行中,因此請耐心等待完成。

語法

它本質上是一個顯示任務進度的訊息框。以下是一個建立進度條的簡單語法。

Ext.MessageBox.show ({
   title: 'Please wait',
   msg: 'Loading items...',
   progressText: 'Initializing...',
   width:300,
   progress:true,
   closable:false
});

示例

以下是一個顯示進度條的簡單示例。

<!DOCTYPE html>
<html>
   <head>
      <link href = "https://cdnjs.cloudflare.com/ajax/libs/extjs/6.0.0/classic/theme-classic/resources/theme-classic-all.css" 
         rel = "stylesheet" />
      <script type = "text/javascript" 
         src = "https://cdnjs.cloudflare.com/ajax/libs/extjs/6.0.0/ext-all.js"></script>
      
      <script type = "text/javascript">
         Ext.onReady(function() {    
            function progressBar(v) {
               return function()	{
                  if(v == 10) {
                     Ext.MessageBox.hide();
                     result();
                  } else {
                     var i = v/9;
                     Ext.MessageBox.updateProgress(i, Math.round(100*i)+'% completed');
                  }
               };
            };
            function showProgressBar() {
               for(var i = 1; i < 11; i++) {
                  setTimeout(progressBar(i), i*500);
               }
            }
            function result() {
               Ext.Msg.alert('status', 'Process completed succesfully');
            }
            Ext.create('Ext.Button', {
               renderTo: Ext.getElementById('buttonId'),
               text: 'Click Me',
               
               listeners: {
                  click: function() {
                     Ext.MessageBox.show ({
                        title: 'Please wait',
                        msg: 'Loading items...',
                        progressText: 'Initializing...',
                        width:300,
                        progress:true,
                        closable:false
                     });
                     showProgressBar();
                  }
               }
            });
         });
      </script>
   </head>
   
   <body>
      <p> Click the button to see progress bar  </p>
      <div id = "buttonId"></div>
   </body>
</html>

以上程式將生成以下結果 −

extjs_components.htm
廣告
© . All rights reserved.