如何解决如何在MVC中处理jQuery Repeater HTML
这是我的.cshtml页面代码,我在此代码中使用jquery转发器正常工作,但是我想在此转发器中添加一些修改,但是我被卡在这里。您可以看到我的代码。
@using (Html.BeginForm("Index","Home",FormMethod.Post,new { enctype = "multipart/form-data",@class = "repeater" }))
{
<div data-repeater-list="">
<div data-repeater-item="">
<div class="col-lg-12 col-md-12 col-sm-12">
<input type="file" name="Docfiles" />
</div>
</div>
</div>
<input data-repeater-create type="button" value="Add" />
<button>Save</button>
}
@section Scripts{
<!-- Import repeater js -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery.repeater/1.2.1/jquery.repeater.js"></script>
<script>
$(document).ready(function () {
$('.repeater').repeater({
// (Optional)
// start with an empty list of repeaters. Set your first (and only)
// "data-repeater-item" with style="display:none;" and pass the
// following configuration flag
initEmpty: true,// (Optional)
// "show" is called just after an item is added. The item is hidden
// at this point. If a show callback is not given the item will
// have $(this).show() called on it.
show: function () {
$(this).slideDown();
},// (Optional)
// "hide" is called when a user clicks on a data-repeater-delete
// element. The item is still visible. "hide" is passed a function
// as its first argument which will properly remove the item.
// "hide" allows for a confirmation step,to send a delete request
// to the server,etc. If a hide callback is not given the item
// will be deleted.
hide: function (deleteElement) {
if (confirm('Are you sure you want to delete this element?')) {
$(this).slideUp(deleteElement);
}
},// (Optional)
// Removes the delete button from the first list item,// defaults to false.
isFirstItemUndeletable: true
})
});
</script>
}
我想像下面的屏幕截图所示那样在此格式中更改html。
解决方法
首先,在jquery.repeater.js中设置名称格式,如果要更改它,则需要更改jquery.repeater.js,这是一个演示示例:
我将js复制到我的项目中,如下所示:
2。在jquery中找到setIndexes
并像这样更改var newName = groupName + '[' + index + '][' + name + ']' +
(也可以将其更改为所需的其他格式):
3。将脚本src从cdnjs更改为您自己的项目:
<script src="~/lib/jquery-repeater/jquery.repeater.js"></script>
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。