jEditable:提交后显示选项文本(而不是值)
我在选择列表上使用 jEditable。除了以下问题之外,它工作得很好。 jEditable 在提交后显示服务器发回的任何内容。这对于文本框等非常有用,您可以在其中简单地从服务器发回提交的值。
然而,这对选择列表没有意义,因为发布的值只是选项元素的 Id。如果我将其发回,那么我的文本将更改为 ID,而不是之前的友好文本。
我怎样才能关闭这种行为?我不想再次使用提交的 ID 从数据库中获取文本值,只是为了将其发回以供显示。应该有一种方法来保留选项文本,然后让 jEditable 在提交后将其放回标签中。帮助?
I'm using jEditable on a Select list. It works beautifully, except for the following issue. jEditable displays in place whatever a server posts back after a submit. That works great for text boxes etc. where you can simply post the submitted value back from the server.
However, this makes no sense on select lists because the value posted is simply the Id of an option element. If I post that back, then my text changes to the Id instead of the friendly text that was there before.
How can I turn this behavior off? I don't want to have to fetch the text value using the submitted Id from from the DB again just to post it back for display purposes. There should be a way to retain the option text and then have jEditable put it back in the label after submission. Help?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
只需在可编辑配置对象中添加一个回调,如下所示:
Just add a callback in the editable configuration object, with this:
快到了。
我对 William Niu 的代码有两个问题。
首先,您无法通过这种方式访问变量数据,请使用settings.data 代替。
其次,变量 data 不是数组,而是字符串,因此 data[value] 不起作用。
这是我的代码,试试这个。
Almost there.
I had two problems with William Niu's code.
First, you can not access to variable data this way, use settings.data instead.
Second, variable data is not an array, but a string, so data[value] will not work.
Here is my code, try this.
jEditable 提供了各种回调函数供您操作数据。这可能取决于您如何获取数据来填充
选择
。例如,如果您的数据是常量映射,则可以轻松地从返回的键中找到值:示例: http ://jsfiddle.net/william/mT4XV/
jEditable provides various callback functions for you to manipulate the data. It may depend on how you obtain the data to populate the
select
. For example, if you the data is a constant map, you can easily find the value from the returned key:Example: http://jsfiddle.net/william/mT4XV/
Hammers 代码中的回调函数是正确的,但我在解析数据时遇到问题:
数据应该符合 json,意味着:
data :
'{"E":"Letter E","F":"Letter F","G":"Letter G"}',
所以正确的代码就像
如果你有一个您可以使用 Niu 的回调来使用简单数组而不是关联数组。
The callback function in Hammers code is correct, but I had problems with parsing the data:
The data should be json-conform, means:
data :
'{"E":"Letter E","F":"Letter F","G":"Letter G"}',
So the correct code is like
If you have a simple array instead of the associative array you can use Niu´s callback.
在回调函数中对我有用:)
in the callback function worked for me :)
我有类似的问题。我正在使用 post 来运行和 loadurl。
通过将
var str = settings.target.apply(self, [input.val(), settings]);
修改为var str = settings.target.apply(self, [input.val ()、设置、输入]);
我可以控制目标函数中的选择元素I had a similar problem. I am using post to function and loadurl.
By modifying
var str = settings.target.apply(self, [input.val(), settings]);
tovar str = settings.target.apply(self, [input.val(), settings, input]);
I had control over the select element in my target function