如何在 webix 应用程序中读取和查看光盘文件

How to read and view a disc file in a webix application

我是 webix 开发的新手,documentation/help 对我目前面临的挑战没有太多了解。

在我的 webix 应用程序中,我想要一个按钮(名称为 'View Report'),单击该按钮将 link 到我本地光盘中的光盘文件并在弹出窗口中显示其内容 window.

我包括了到目前为止我可以编写的代码片段:

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 函数如下所示(取自 http://docs.webix.com/desktop__window.html)

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

})      
}

单击该按钮应该读取驻留在我的目录中的文件(比如 C:\Users\myname\Desktop\report.txt")并在模式 window 中显示该文件内容。它可以是任何弹出窗口window 用关闭按钮显示文件内容。有人能帮我实现吗?我很抱歉不能在这里放太多代码,因为我是新手。

我还包括一个工作代码,它允许用户从他的目录中选择一个文件并在文本区域中显示其内容。

<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>

谢谢。

这里是一个示例,但请记住,有很多方法可以执行此操作,并且该示例不应该最适合您的具体情况:

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"
        }
    });