AngularJS,DropzoneJS,JSON - 成功上传时刷新文件列表

时间:2015-02-14 14:00:21

标签: javascript php json angularjs dropzone.js

我有"文件管理器页面"使用DropzoneJS(用于上传)和AngularJS ng-repeat用于显示所有已保存的文件(通过ng-controller,其中http.gets json文件包含文件列表)。

DropZoneJS罢工事件"成功发送"我想刷新角度显示的文件列表。

有没有办法如何实现这一点,或模型完全错误(据我想从dropzone事件中调用ng-controller函数)?

实际代码:



<div class="container">
	<div ng-app="" ng-controller="filesController">
		
		<input ng-model="searchText">
		
		<table class="table table-striped">
			<thead>
				<tr>
					<th>File Name</th>
					<th>File Size</th>
				</tr>
			</thead>
			<tbody>
				<tr ng-repeat="x in files | filter:searchText | orderBy:'name' ">
					<td>{{ x.name }}</td> <td>{{ x.filesize }}</td>
				</tr>
			</tbody>
		</table>
	</div>
</div>
    <script src="js/dropzone.js"></script>
    <script>
    	var myDropzone = new Dropzone("div#myId", { url: "content/uploadscript.php"});

    	myDropzone.on("queuecomplete", function(progress) {
    		 //location.reload(); //refreshing file list
    	});	

    	function filesController($scope,$http) {
    	    $http.get("content/files.php?list")
    	    .success(function(response) {$scope.files = angular.fromJson(response);  });
    	}
    </script>
&#13;
&#13;
&#13;

提前谢谢

1 个答案:

答案 0 :(得分:1)

$scope.$on('successfullupload',function(event,data){
  $scope.list=data;
  //assuming $scope.successfullupload was broadcast, and can pass a json which contains the new list
});

我相信对事件的反应是你的情况。

您需要将dropzone事件侦听器放在控制器中,如下所示:

<script>
    function filesController($scope,$http) {
        $http.get("content/files.php?list")
        .success(function(response) {$scope.files = angular.fromJson(response);  });//get initial $scope.files value

var myDropzone = new Dropzone("div#myId", { url: "content/uploadscript.php"});

    myDropzone.on("queuecomplete", function(progress) {//event listener
         $http.get("content/files.php?list")
        .success(function(response) {$scope.files = angular.fromJson(response);  });//will refresh $scope.files
    });
    }
</script>