2016-12-12 51 views
-1

我有一个问题:如何从控制器打开文件?

我有一个AngularJS应用程序。我有一张桌子和几个输入栏。其中一个输入字段是文本区域。

我需要代码从表中获取数据,并将其放入输入字段。

现在,textarea字段显然需要大量文本。
而那个大文本,我不需要在我的数据库上。
我想从文件夹中取出文件的名称,然后在我的文件夹中进行搜索,如果该文件存在,并且如果存在,我需要将它的内容显示在textarea上。

这是迄今为止代码:

HTML页面

<label>Script ID:</label> 
    <input 
     name="scriptId" 
     type="text" 
     ng-model="selectedScript.scriptId" 
     value="{{selectedScript.scriptId}}" 
     /> 
    <br /> 

    <label>File Name:</label> 
    <input 
     type="text" 
     ng-model="selectedScript.fileName" 
     value="{{selectedScript.fileName}}" /> 
    <br /> 

<div id="container"> 
     <textarea ng-model="selectedScript.src" 
      value="{{selectedScript.src}}" id="fileInfo"></textarea> 
</div> 

<table class="scripts"> 
    <tr bgcolor="lightgrey"> 
     <th>Script ID</th> 
     <th>File Name</th> 
    </tr> 
    <tr 
     ng-repeat="s in scripts | filter:searchField | orderBy:'scriptId'" 
     ng-click="selectScript(s)" 
     ng-class="getSelectedClass(s)" >   

     <td>{{s.scriptId }}</td> 
     <td>{{s.fileName }}</td> 
    </tr> 
</table> 

而且控制器

//some function to show what attributes the script has 
$scope.scripts.push({ 
    'scriptId' : selectedScript.scriptId, 
    'fileName' : selectedScript.fileName, 
    'src' : selectedScript.src, 
    'userId' : 1 //hardcoded, for now 
}); 

$scope.selectedScript = {}; 
$scope.selectedRow = null; 

$scope.selectScript = function(script) { 
    $scope.selectedScript = script; 
    //At this point i have the file name, i just need to open the 
    //file, and read it, and push the data to my textarea 
}; 

回答

1

你不能访问文件系统一样,从JS。

根本没有办法以编程方式通过JS访问您的计算机的文件。

+0

k ...我会寻找另一种方式 – newbie

+1

幸运的是......! – Mistalis

相关问题