【问题标题】:updating x-editable input field based on returned value根据返回值更新 x-editable 输入字段
【发布时间】:2013-12-04 03:48:46
【问题描述】:

在我的 x-editable 字段中,我有一个要根据返回值更新的文本区域。这在我使用$(this).html(newVal); 时有效,如下所示

success: function(response, newValue) {
  newVal=unescape(JSON.parse(response).VALUE)
  $(this).html(newVal);
}  

问题是当我第二次点击编辑字段时,输入对象(类:editable-input)内的值与发送时保持不变。有办法解决这个问题吗?

【问题讨论】:

    标签: javascript x-editable


    【解决方案1】:

    最简单的方法:

            $('.textarea').editable({
                success: function(response, newValue) {
                        return {newValue: response.newValue};
                    }
                }
            });
    

    记得在响应内容中返回 newValue 变量:

    {"newValue":"some_string_new_value"}
    

    【讨论】:

    • 我有同样的问题,但我想以编程方式更改字段的值。在我单击编辑值之前,一切看起来都是如此;旧的出现了。
    【解决方案2】:

    这行得通。我通过在on success 回调中调用此函数来设置值

      function formatXEditable($item, $val){
        $val = $val.replace(/<br\s*\/?>/mg,"\n");
        $($item).on('shown', function(e, editable) {
          editable.input.$input.val($val);
        });
      }
    

    【讨论】:

    • 看我上面的回答
    猜你喜欢
    • 2013-04-22
    • 1970-01-01
    • 2019-07-20
    • 1970-01-01
    • 2013-05-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多