首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在mvc中处理jquery中继器html

如何在mvc中处理jquery中继器html
EN

Stack Overflow用户
提问于 2020-09-16 17:10:45
回答 1查看 2K关注 0票数 1

这是我的.cshtml页面代码,我使用jquery中继器是在这个代码中继器工作很好,但我想在这个中继器中添加一些修改,但我被困在这里。你可以看到我的密码。

代码语言:javascript
复制
@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,如下图所示。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-09-17 03:18:04

首先,名称格式是在jquery.repeater.js中设置的,如果您想要更改它,需要更改jquery.repeater.js,下面是一个演示:

1.将jquery.repeater.js添加到项目中。

我将js复制到我的项目中如下所示:

2.在jquery中找到setIndexes并像这样更改var newName = groupName + '[' + index + '][' + name + ']' +(您也可以将它更改为您想要的其他格式):

3.将脚本src从cdnjs更改为您自己的项目:

代码语言:javascript
复制
<script src="~/lib/jquery-repeater/jquery.repeater.js"></script>

4.结果:

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/63924939

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档