jQuery 和Rails 3 - 回调
我正在尝试使用两个参数制作自己的确认对话框。
function myAlert(message, adr) {
jConfirm(message, 'Confirmation Dialog', function(answer) {
if (answer){
window.location = adr;
}
});
}
$(document).ready(function() {
$.rails.confirm = function(mess, mess2) {
return myAlert(mess, mess2);
}
});
在视图中:
<%= link_to 'Delete',
{:controller => 'controller_name', :action => 'action_name'},
:confirm => {"xxxxxxx", "aaaaaaaa"} %>
在警报消息中我将收到以下信息: xxxxxxaaaaaaaa
我做错了什么?为什么我不能只得到 xxxxxxx?为什么字符串要合并?
PS:jConfirm函数中的第一个参数显示消息确认窗口。
I am trying to make my own confirm dialogs with two parameters.
function myAlert(message, adr) {
jConfirm(message, 'Confirmation Dialog', function(answer) {
if (answer){
window.location = adr;
}
});
}
$(document).ready(function() {
$.rails.confirm = function(mess, mess2) {
return myAlert(mess, mess2);
}
});
And in view:
<%= link_to 'Delete',
{:controller => 'controller_name', :action => 'action_name'},
:confirm => {"xxxxxxx", "aaaaaaaa"} %>
And in alert message I will get following:
xxxxxxxaaaaaaaa
What I am doing wrong? Why I don't get only xxxxxxx? Why are the strings merged?
PS: the first parameter in jConfirm function display the message to confirm window.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我相信
:confirm
只是一个字符串参数。我有点惊讶,因为:confirm =>如果我没记错的话, {"xxxxxxx", "aaaaaaaa"}
应该会抛出语法错误。如果你想传递两个参数,你可以将它们存储在单独的数据属性中并推出你自己的确认方法,如下所示:
或者你用逗号分隔你的参数并使用 JS 拆分它们:
I believe
:confirm
is a string argument only. I'm a bit surprised, because:confirm => {"xxxxxxx", "aaaaaaaa"}
should throw a syntax error if I'm not mistaken.If you want to pass two parameters, you could store them in separate data attributes and roll your own confirmation method, something like this:
Or you comma-separate your arguments and split them using JS: