在data-*属性中成功回调x可编辑编码
X-editable encoding success callback in data-* attribute
我正在使用X-editable创建可以通过ajax调用就地编辑的链接。
我的页面上所有可编辑的都是用类edititable创建的,并使用data-*参数将值传递给x-editable。总的来说,这是可行的,因为更新提交得很好。
然而,在下面的例子中,data-success函数从来没有调用过——在这种情况下,我从来没有看到控制台日志。
<a href="#"
class="editable"
data-type="select"
data-send="always"
data-source='{"Windows 2000":"Windows 2000","Windows Server 2003":"Windows Server 2003","Windows Server 2008":"Windows Server 2008","Windows Server 2008 R2":"Windows Server 2008 R2","Windows Server 2012":"Windows Server 2012","Windows Server 2012 R2":"Windows Server 2012 R2","Other":"Other"}' data-name="Value"
data-pk="1155"
data-display="function (value, response) { return false;}"
data-success="function (response, newValue) { console.log('success');}"
data-url="/attribute/updateField"
data-title="Title info">Windows Server 2008</a>
我问过x -edit的程序员,因为我也在尝试同样的事情,他回答说这是不可能的。他的回答:
我认为这是不可能的,因为数据属性被解析,但不像javascript那样eval。
我也认为更好的方法是将js逻辑存储在js文件中,而不是在html属性中。
我找到的最干净的解决方案是:
HTML:<a href="#"
class="editable"
data-type="select"
data-send="always"
data-source='{"Windows 2000":"Windows 2000","Windows Server 2003":"Windows Server 2003","Windows Server 2008":"Windows Server 2008","Windows Server 2008 R2":"Windows Server 2008 R2","Windows Server 2012":"Windows Server 2012","Windows Server 2012 R2":"Windows Server 2012 R2","Other":"Other"}' data-name="Value"
data-pk="1155"
data-eval-display="console.log('display', response, newValue);"
data-eval-success="console.log('success', response, newValue);"
data-url="/attribute/updateField"
data-title="Title info">Windows Server 2008</a>
JavaScript: $('.editable').editable({
display: function(response, newValue) {
eval($(this).data('eval-display'));
},
success: function(response, newValue) {
eval($(this).data('eval-success'));
}
});
相关文章:
- CKEditor Widget-阻止编辑可编辑元素本身
- 如何在angularJS中编辑时,如果DB中的值为true,则设置复选框,如果值为false,则取消选中复选框
- 高亮显示时编辑文本大小和颜色
- 剑道UI内联编辑:如何在点击其他按钮时隐藏按钮
- 将事件聚焦/模糊在可编辑内容的元素上
- 编辑HTML表的源数据
- 将地理编码结果转换为php变量以发布到mysql数据库
- ExtJS网格单元格编辑器,防止焦点松动问题
- 如何在visualstudio中调试web api时编辑javascript文件
- 具有所有样式的文本正在复制到可编辑文本区域
- 可以't使用PHP使用Froala编辑器上传图像URL
- 用Greasemonkey编辑专栏
- 如何在corona sdk中从CK编辑器中检索数据
- 编辑HTML5演示文稿,无需编码
- 解码编码的 javascript,编辑,然后再次编码
- 编码后如何编辑 JSON 数组
- 使用TinyMCE编辑器的javascript对文本区域中的输入进行编码
- 如何在php中编码数组,将其保存为cookie,在js中编辑并再次保存
- 在data-*属性中成功回调x可编辑编码
- JS生成的不可编辑的DIV不能在Chrome中聚焦(和模糊),直到静态HTML编码可以