0

I have a webpage which displays contents of a folder/directory upon clicking on it. If the contents of a folder has files, then download button is activated. If the contents of the folder is a directory, download button is inactive.

Here is my code that is supposed to make that work. But the Download button remains active all the time and never goes inactive. Can somebody point out where I'm going wrong ?

$scope.IsFile = function(filenames){
		forEach(filenames, function(filename){
			if(filename.indexOf(".zip") > 1|| filename.indexOf(".txt") >1 || filename.indexOf(".xml") > 1 )	{
				return true;
			}
			else {
				return false;
			}
		});
	};
<div class="col-md-3" id="CTP Jobs">
		<div ng-click="GetListOfFilesonCTP('/home/topas/rda_app/JOBS/')">
			<a href="">
				<h3>
					JOBS <small> <span class="btn-group"
						role="group">
							<button type="button" class="btn btn-default" ng-disabled="IsFile(listOfFilesOnJobs)"
								ng-click="download()">Download</button>
					</span>
					</small>
				</h3>
			</a>
		</div>
		<table class="table table-striped"
			ng-init="GetListOfFilesonCTP('/home/topas/rda_app/JOBS')">
			<tr ng-repeat="jobs in listOfFilesOnJobs"
				ng-click="GetListOfFilesonCTP(getPath('/home/topas/rda_app/JOBS/', jobs))">
				<!--'/home/topas/rda_app/JOBS/'+ jobs + '/'  -->
				<td><a href="">{{jobs}}</a></td>
			</tr>
		</table>
	</div>

4

1 回答 1

1

您的IsFile函数没有显式返回任何内容(即它返回undefined)并将其ng-disabled解释为false. 第4 行return truereturn false第 7 行的 and 与传递给的函数有关forEach,这可能不是您想要的。您的意思是过滤文件列表并检查是否有剩余文件?这样的事情会做:

$scope.isFile = function(filenames) {
    return filenames.filter(function(filename) {
        return filename.indexOf(".zip") > 1 || 
            filename.indexOf(".txt") > 1 || 
            filename.indexOf(".xml") > 1
    }).length > 0
}
于 2016-04-20T22:18:02.553 回答