【问题标题】:rendering the copy of the field on the button click在按钮单击时呈现字段的副本
【发布时间】:2020-05-28 20:22:48
【问题描述】:

我有一个字段,我想通过单击按钮来倍增。我什至不知道从哪里开始?

到目前为止我唯一的代码。 fieldDef 是最初由 wtforms 渲染的字段定义:

    this.fieldDef = params.fieldDef
    var that = $('#' + this.fieldDef["name"]);

    this.init = function() {
       that.after('<input id="addBtn" type="button" value="Add another"/>')
       $("#addBtn").click(function(){
         //this.fieldDef.render()??
       })
     }
     this.init()

能否请您指出一些有想法的资源?

【问题讨论】:

    标签: jquery flask-wtforms


    【解决方案1】:

    你能用例子多解释一下你的想法吗?

    据我了解,在我看来,克隆正是您需要的想法。 看一下这个: https://api.jquery.com/clone/

    // Original element with attached data
    var $elem = $( "#elem" ).data( "arr", [ 1 ] ),
        $clone = $elem.clone( true )
          // Deep copy to prevent data sharing
          .data( "arr", $.extend( [], $elem.data( "arr" ) ) );
    

    【讨论】:

    • 这正是我所需要的!谢谢!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-05-29
    • 2017-10-12
    • 2018-05-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多