【问题标题】:Is it possible to submit a hidden field and control its value with x-editable?是否可以提交隐藏字段并使用 x-editable 控制其值?
【发布时间】:2013-07-11 08:31:32
【问题描述】:

在X-editable的文档中,我们可以新建一条记录,但是如何编辑一条已有的记录,并把它的name和email字段以及它的id =1(这个id没有改变)发布到后端呢?

<table>
    <thead><th>id</th><th>name</th><td>email</th></thead>
    <tbody>
        <tr><td><span>1</span></td><td><span class='myeditable'>name</span></td><td><span class='myeditable'>email@example.com</span></td></tr>
    </tbody>
</table>

$('.myeditable').editable({
    type: input,
    url: '/edituser'
});

$('#save-btn').click(function() {
    $('.myeditable').editable('submit', {
        url: '/edituser',
        ajaxOptions: {
            dataType: 'json' //assuming json response
        },
        success: function(data, config) {
            if(data && data.id) { //record created, response like {"id": 2}
            },
            error: function(errors) {
            }
    });
});

【问题讨论】:

    标签: submit field hidden x-editable


    【解决方案1】:

    我使用 Angular-xeditable 来做到这一点,但我认为这个想法是一样的。

    我在我的表中添加了一个隐藏的跨度并给它一个电子名称。 ng-show 设置 display:none,我认为这也是你需要做的。

              <span
                editable-text="journalEntry._id"
                e-name="_id" 
                e-form="rowform"
                ng-show="false">
              </span>
    

    【讨论】:

      【解决方案2】:

      我也使用了 Angular-xeditable,但不得不更改 Michael 的代码,因为当我编辑该行时出现了隐藏字段(我希望它保持隐藏)。

      因此我不得不插入

          e-class="hidden"
      

      所以最后我得到了:

                                      <span 
                                          e-class="hidden"
                                          editable-text="employee.key"
                                          e-name="key"
                                          e-form="rowform"
                                          ng-show="false">
                                      </span>
      

      【讨论】:

        【解决方案3】:

        要发布隐藏字段,您可以尝试修改您的

        url: '/edituser'

        到

        url: '/edituser?hidden-name1=hidden-value1&amp;hidden-name2=hidden-value2'等等……

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2015-05-30
          • 1970-01-01
          • 1970-01-01
          • 2014-08-14
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多