我目前正在使用jEditable插件来撰写可更新的文本。我的服务器端是用Struts2开发的,我调用的服务器url是返回JSON结果的struts操作。我使用以下代码将可编辑文件加载到我的字段(这是一个H1):
$("h1.myclass").editable("/MyApp/dinamic/updateText.action", {
indicator : "<center><img src='/MyApp/images/loading.gif'></center>",
submit : 'Save',
cancel : 'Cancel',
tooltip : "Click to edit",
onblur : "ignore",
name : "myField",
callback : function(value, settings) {
alert(JSON.stringify(value));
}
});
可以看到,在这段代码中,我还没有使用type : autogrow
功能,到目前为止它工作得很好。问题是,当我添加type : autogrow
时,显示相应的文本,但当我单击保存按钮时,浏览器被重定向到一个url,如
http://localhost:8080/MyApp/myform.action?myfield=YadaYada
其中YadaYada
是我试图保存的实际文本,myform.action
是我已经保存的页面。
有人知道为什么这个bug会出现吗?
OBS:我也尝试使用growfield2而不是自动增长,结果是相同的。
好吧,所以我不完全确定如果我是正确的,但我一直试图解决这个问题自己。我发现的是,如果你的代码"稍微"关闭,那么它会导致页面重新路由。我已经得到了自动增长的工作,我相信这应该为您工作:
$.editable.addInputType('autogrow', {
element: function (settings, original) {
var textarea = $('<textarea />');
if (settings.rows) {
textarea.attr('rows', settings.rows);
} else {
textarea.height(settings.height);
}
if (settings.cols) {
textarea.attr('cols', settings.cols);
} else {
textarea.width(settings.width);
}
$(this).append(textarea);
return (textarea);
},
plugin: function (settings, original) {
$('textarea', this).autogrow(settings.autogrow);
}
});
$("h1.myclass").editable("/MyApp/dinamic/updateText.action", {
type: "autogrow",
indicator: "<center><img src='/MyApp/images/loading.gif'></center>",
submit: 'Save',
cancel: 'Cancel',
tooltip: "Click to edit",
onblur: "ignore",
name: "myField",
callback: function (value, settings) {
alert(JSON.stringify(value));
},
autogrow: {
lineHeight: 16,
maxHeight: 512
}
});