简体   繁体   English

如何使用KnockoutJS数据绑定将使用GridFS的已上传文件的信息显示到表中

[英]How to display information of uploaded files using GridFS to a Table using KnockoutJS data-bind

How can I display information of an uploaded file (File Name, File Size, Date Uploaded) to a table in an express page? 如何在快速页面的表格中显示上载文件的信息(文件名,文件大小,上载日期)? I am using knockoutJS as the front-end. 我正在使用基因敲除JS作为前端。 The uploaded files are uploaded to a MongoDB database using GridFS. 使用GridFS将上传的文件上传到MongoDB数据库。

 <script src="https://cdnjs.cloudflare.com/ajax/libs/knockout/3.4.2/knockout-min.js"></script> <thead> <tr> <th class="col-sm-4">File Name</th> <th class="col-sm-2">File Type</th> <th class="col-sm-3">File Size</th> <th class="col-sm-2">Date of Upload</th> <th class="col-sm-1">Controls</th> </tr> </thead> <tbody data-bind=""> <tr class="gradeX"> <td data-bind="<!-- File Name -->"></td> <td data-bind="<!-- File Type -->"></td> <td data-bind="<!-- File Size -->"></td> <td data-bind="<!-- Date of Upload -->"></td> <td class="center"> <a href="#" data-bind="click: " data-toggle="tooltip" title="View File Details"><i class="fa fa-info-circle text-navy"></i></a> <a href="#" data-bind="click:" data-toggle="tooltip" title="Remove File"><i class="fa fa-trash text-navy"></i></a> <a href="#" data-bind="click:" data-toggle="tooltip" title="Download File"><i class="fa fa-download text-navy"></i></a> </td> </tr> </tbody> 

Thank you in advance! 先感谢您! Hoping for a positive response. 希望得到积极的回应。

Assuming you are binding to a KnockoutJS view model with a populated array (doesn't have to be a ko.observableArray ) named files : 假设您使用命名files绑定到具有填充数组(不必是ko.observableArray )的KnockoutJS视图模型:

 class ViewModel { constructor() { this.files = [{ fileName: "A", fileType: "B", fileSize: 1, dateOfUpload: "2018-03-14" }, { fileName: "C", fileType: "D", fileSize: 2, dateOfUpload: "2018-03-15" }]; this.viewFileDetails = this.viewFileDetails.bind(this); this.removeFile = this.removeFile.bind(this); this.downloadFile = this.downloadFile.bind(this); } viewFileDetails() { return; } removeFile() { return; } downloadFile() { return; } } const vm = new ViewModel(); ko.applyBindings(vm); 
 <script src="https://cdnjs.cloudflare.com/ajax/libs/knockout/3.4.2/knockout-min.js"></script> <table> <thead> <tr> <th class="col-sm-4">File Name</th> <th class="col-sm-2">File Type</th> <th class="col-sm-3">File Size</th> <th class="col-sm-2">Date of Upload</th> <th class="col-sm-1">Controls</th> </tr> </thead> <tbody data-bind="foreach: files"> <tr class="gradeX"> <td data-bind="text: fileName"></td> <td data-bind="text: fileType"></td> <td data-bind="text: fileSize"></td> <td data-bind="text: dateOfUpload"></td> <td class="center"> <a href="#" data-bind="click: $root.viewFileDetails" data-toggle="tooltip" title="View File Details"><i class="fa fa-info-circle text-navy"></i></a> <a href="#" data-bind="click: $root.removeFile" data-toggle="tooltip" title="Remove File"><i class="fa fa-trash text-navy"></i></a> <a href="#" data-bind="click: $root.downloadFile" data-toggle="tooltip" title="Download File"><i class="fa fa-download text-navy"></i></a> </td> </tr> </tbody> </table> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM