使用:display_as -我如何更新<input>还有<span>
best_in_place using :display_as - how do I update the value of the <input> as well as the <span>
我有一个best_in_place
表单,我正在做一些提交的数据的后处理。这是一系列的时间,我在保存之前将它们格式化成一致的格式。我如何得到更新后的值显示在保存后的形式?
我只能找到一种略显粗糙的方法来做到这一点。首先,将表单帮助器上的display_as
参数设置为与显示的实际属性相同。
= best_in_place @post, :name, type: :input, :display_as => :name
然后,为best_in_place:success
添加一个javascript处理程序
$(document).on('best_in_place:success', function(e, data) {
$(this).data('bestInPlaceEditor').original_content = data['display_as'];
});
当文章保存并更新name
属性时,新值将以JSON形式返回:它将看起来像{"display_as": "updated post name"}
。此javascript获取返回的值并将其设置为BIP编辑器的original_content
属性。当BIP呈现输入时(当您单击帖子名称进行编辑时),将显示original_content
的值。
使用best_in_place 2.1.0测试。best_in_place.js中的相关代码如下:
if (response !== null && response.hasOwnProperty("display_as")) {
this.element.attr("data-original-content", this.element.text());
this.original_content = this.element.text();
this.element.html(response["display_as"]);
}
这里this.element
是字段未被编辑时的显示。所以,它被设置为与original_content
不同的值(这是渲染时得到的)。我不确定这是有意的还是best_in_place中的一个bug。
相关文章:
- Javascript循环不会自我更新
- 添加文字和评论功能更新Div
- AngularJS:ng之后,重复$scope值未按预期更新
- 如何通过数组更新角度子范围
- Ajax聊天消息重复而不仅仅是更新
- 正在将base64 jpeg从input-type=file上传到服务器
- 通过CSV文件上载更新数据库表
- 平均值:无法将数据更新到数据库
- $rootScope未使用forEach进行更新
- d3基于用户选择动态更新节点
- 有条件更新d3.js力图中节点的最佳方法
- Angular:更新一次性绑定的数据
- Javascript更新孙窗口中的表单元素
- 使用AngularJS中的筛选器更新给定的表
- 从选项页面更新chrome扩展清单权限
- 如何在不刷新页面的情况下更新显示框
- 使用javascript将span更改为input(viceversa),然后AJAX更新输入
- md-char-count 未在 md-input-container 中更新
- angular2 @Input EventEmitter更新视图
- React Input Range更新状态缓慢