- xml - AJAX/Jquery XML 解析
- 具有多重继承的 XML 模式
- .net - 枚举序列化 Json 与 XML
- XML 简单类型、简单内容、复杂类型、复杂内容
我正在实现拖放 文件,例如this在 ASP.NET MVC 5 中,但我的要求是当我拖动文件时,它不应该立即上传。首先拖动文件,然后单击按钮(“输入元数据”)为每个文件输入一些强制属性(元数据名称、类别等...),然后点击其他按钮(提交)提交上传。
通常当我们拖动文件时,它会立即上传,我必须停止它并在单击按钮时执行(在填写其他字段后)。甚至任何具有类似功能的第三方 js 库?
我用谷歌搜索了很多但没有得到预期的结果。有人可以指导我如何满足此要求或提供一些链接来满足此要求。
最佳答案
您链接到的示例代码似乎正在使用 jquery.filedrop.js,它是由 Weixi Yen 编写的。您需要从其project home 下载并使用最新版本。为了这个工作。
您还应该下载并使用比与该示例代码捆绑在一起的更高版本的 jquery。我已经用 jquery 1.9.1 对此进行了测试。
要使用您选择的 jquery 扩展,您需要利用 beforeSend
选项,并提供您自己的函数。您还需要存储对为每个文件的自定义函数提供的 done()
函数的引用,以便稍后调用它们,从而上传文件。
如果您希望为每个文件显示元框,则需要在每个文件的基础上附加适当的 html 以允许用户填写它们。
我建议的代码摘要如下:
var uploads_to_call = []; // the global to store all the file upload callbacks
$('#dropzone').filedrop({
fallback_id: 'upload_button', // an identifier of a standard file input element, becomes the target of "click" events on the dropzone
url: 'upload.php', // upload handler, handles each file separately, can also be a function taking the file and returning a url
// other important parameters related to upload, read the documentation for details
// this is the important custom function you need to supply
beforeSend: function(file, i, done) {
// file is a file object
// i is the file index
// call done() to start the upload
// this is just to clone meta boxes for the user to fill in for each file
// it also fills in the filename so that it's obvious which meta boxes
// are for which files
$("#perfile").children().clone()
.appendTo("#allmeta")
.children(".filename").html(file.name);
// this pushes the done() callback into the global mentioned earlier
// so that we can call it later
uploads_to_call.push(done);
},
afterAll: function() {
// runs after all files have been uploaded or otherwise dealt with
// you should possibly put code in here to clean up afterwards
}
});
// set a handler to upload the files when the submit button is clicked
$("#submit").click(function(){
$.each(uploads_to_call, function(i, upcall) {
upcall();
});
});
使用类似于下面的html:
<form>
<div id="dropzone"></div>
<div id="allmeta"></div>
<button id="submit">submit</button>
</form>
<div id="perfile">
<div class="meta">
<span class="filename"></span>
<input type="text" placeholder="meta"/>
<input type="text" placeholder="meta"/>
</div>
</div>
div#perfile
应该有 css 来隐藏它,因为它只用于包含每次拖入文件时要克隆到表单中的 div。
我已经创建了一个概念证明 jsfiddle here ,显然这实际上不允许上传文件,但它显示了 JS 方面的工作。您需要向下滚动到 javascript 面板的底部才能看到自定义代码 - 顶部的内容只包括您应该从项目主页网站下载的 javascript 扩展。
这应该足以让您在 asp.net 方面正常工作。您只需以您认为合适的方式发布用户提供的额外元数据。
显然这是准系统,您应该根据需要充实它。
关于javascript - 拖放和提交文件以上传,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32764201/
这个问题在这里已经有了答案: Difference between Property and Field in C# 3.0+ (10 个答案) 关闭 10 年前。 我不明白静态属性之间的区别: p
当元素被拖放时,有没有办法从被拖动的元素中获取 id(或其他属性值)? 例如,在左侧,我有一堆 div,我可以将图像放入其中。右边有一个 div 用来保存图像。当我将图像从右侧拖动到左侧的 div 时
每当我更改其中一个类属性时,我想设置一个修改标志,如下所示 public bool Modified { get; set; } public bool Enabled { get; set { Mo
由于某种原因,我下面的代码曾经可以正常工作,但现在却引发了一个异常: public static async Task HttpPut(string inUrl, string inFilePath)
为什么将 ; 放在最佳实践中?在函数定义的末尾。 例如 var tony = function () { console.log("hello there"); }; 优于: var tony
我在容器内有一个位图。当我拖动容器时,光标变为编辑文本形状,图像也跳到光标的右下角(好像我从左上角拿着图像并拖动它)。 这是我的代码,所以你可以看到我有 RTFM: function createIc
这个问题已经有答案了: C# 3.0 auto-properties — useful or not? [closed] (17 个回答) 已关闭 6 年前。 当我让 Visual Studio 20
以类中的以下代码为例: public class Employee : IEntity { public string FirstName { get; set; } public s
我有 json 数据: { "products": [ { "productId" : 0, "productImg" : "../img/product-ph
这个问题在这里已经有了答案: What is the difference between a field and a property? (33 个答案) 关闭 9 年前。 我在一本书上找到这样声
我正在设置多个方法,想知道如何继续将一个变量(“顶部”变量)传递给不同的方法。 主要方法: public static void Main(string[] args) { i
我正在尝试使用 crontab 编写一个简单的任务,将一些文件从本地复制到 HDFS。我的代码是这样的: #!/bing/ksh ANIO=$(date +"%Y") MES=$(date +"%m"
有人可以告诉我如何使用这个解决方案来解决我的问题吗?我也想限制 id 中包含文本“not”的节点的拖/放。 jsTree drag and drop restrict folders by class
我的情况如下 - 我正在对可能包含链接行的表进行排序: row 1 row 2 row 3 row 4 row 5 我需要的是禁止在.linked-to-p
我想知道是否有人知道是否有一个预先制定的解决方案:我在 ASP.net 网站上有一个列表,我希望用户能够通过拖放对列表进行重新排序。此外,我希望有第二个列表,用户可以将第一个列表中的项目拖到其中。 到
我在理解似乎不一致的方案中的破坏性操作时遇到问题。即为什么下例中bar没有变化 (define foo '(a b)) (define bar foo) (set! foo '(c d)) foo >
我想知道是否有人知道是否有一个预先制定的解决方案:我在 ASP.net 网站上有一个列表,我希望用户能够通过拖放对列表进行重新排序。此外,我希望有第二个列表,用户可以将第一个列表中的项目拖到其中。 到
我在理解似乎不一致的方案中的破坏性操作时遇到问题。即为什么下例中bar没有变化 (define foo '(a b)) (define bar foo) (set! foo '(c d)) foo >
我在我的 Web 应用程序中使用 Ajax ControlToolkit 中的 ModalPopupExtender。我将其 Drag 属性设置为 true,但是当我拖动弹出面板并将其放到新位置时,它
所以,基于this answer ,我有一组可以拖放并卡入到位的 div。唯一的问题是,可拖动的 div 具有不同的高度,我需要它们始终捕捉到目标的底部,而不是顶部。 您可以在this JsFiddl
我是一名优秀的程序员,十分优秀!