2017-04-04 60 views
0

我是webix開發人員的絕對新手,並且找不到有關當前挑戰的大量文檔/幫助。如何閱讀和查看webix應用程序中的光盤文件

在我的webix應用程序中,我希望有一個按鈕(名稱爲'View Report'),它將鏈接到本地​​光盤中的光盤文件,並在彈出窗口中顯示其內容。

我包括了代碼段,我可以迄今寫:

mytoolbar = 
    {    id:'tb', 
       view: 'toolbar', 
       height: rowHeight, 
       type: 'clean', 
       cols: [ 
{view:"button", id:"showfile", type:"icon", icon:"external-link", label:"View Report", width:buttonWidth, tooltip: "click to view report", on: {onItemClick:function(){viewReportFile()}} }, 

] 

而且viewReportFile函數看起來如下

function viewReportFile(){ 
    webix.ui({ 
     view:"window", 
     height:250, 
     width:300, 
     left:50, top:50, 
     move:true, 
     resize: true, 
     head:"This window can be resized", 
     body:{ 
      template:"Some text" 
     } 
    }).show();  

})  
} 

點擊按鈕應讀(從 http://docs.webix.com/desktop__window.html拍攝)一個駐留在我的目錄中的文件(可以在C:\ Users \ myname \ Desktop \ report.txt中說),並在模式窗口中顯示該文件的內容,可以是任何彈出窗口,用關閉按鈕顯示文件內容。任何人都可以幫助我嗎?他執行?我很抱歉無法在此處插入太多代碼,因爲我是新手。

我還包括一個工作代碼,它允許用戶從他的目錄中選擇一個文件並在textarea中顯示其內容。

<html> 

<input type="file" onchange="onFileSelected(event)"> 
<br> 
<textarea id="result" rows="10" cols="50"></textarea> 
<script> 
function onFileSelected(event) { 
    var selectedFile = event.target.files[0]; 
    var reader = new FileReader(); 

    var result = document.getElementById("result"); 

    reader.onload = function(event) { 
    result.innerHTML = event.target.result; 
    }; 

    reader.readAsText(selectedFile); 
} 

</script> 
</html> 

謝謝。

+1

Webix是一個用戶界面框架。它可以使用ajax請求從JSON或XML文件加載數據。其餘的你必須編寫自己的代碼來將數據加載到webix組件中。 –

+0

@ fabien-michel感謝您的回覆。剛纔我編輯了這個問題來添加一個我的需求的實例。您可以在webix中實施時如何使用或適合該代碼,請幫助我嗎? –

回答

1

這裏的樣品,但請記住,有很多來執行這樣的,這個樣本不應該是最適合您的具體情況:

http://webix.com/snippet/36341f3c

function loadReport() { 
    return "My report string"; 
} 

function viewReportFile() { 
    $$('myContent').define('template', loadReport()); 
    $$('myPopup').show(); 
} 


webix.ui({ 
     id: 'myPopup', 
     view:"window", 
     height:250, 
     width:300, 
     left:50, 
     top:50, 
     move:true, 
     resize: true, 
     head:"This window can be resized", 
     body:{ 
      id: 'myContent', 
      template: "Some text" 
     } 
    }); 
相關問題