0

这是问题所在。

My Partial / Modal 中的代码_form.html.erb

<div class="modal-footer">
    <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
    <%= f.submit 'Store Ticket', :class => 'btn btn-primary' %>
    <%= f.submit 'Print Ticket', :name =>'Print Ticket ', :class => 'btn btn-primary', :id => 'print', :onclick => "$.print_page(#{@ticket.id});" %>

这调用了我的函数tickets.js.erb

$(document).ready(function() {
    $.print_page = function(val) {
        var val,
            left = ($(window).width() / 2) - (900 / 2),
            top  = ($(window).height() / 2) - (600 / 2);

        window.open("tickets/print?id=" + val, null, "height=600,width=800,top=" + top + ",left=" + left + ",status=yes,toolbar=no,menubar=no,location=no");
    };

    $.reprint_page = function(val) {
        var val,
            left = ($(window).width() / 2) - (900 / 2),
            top  = ($(window).height() / 2) - (600 / 2);

        window.open("./print?id=" + val, null, "height=600,width=800,top=" + top + ",left=" + left + ",status=yes,toolbar=no,menubar=no,location=no");
    };
});

反过来,这会打开我的 /print,它在嵌入式 java 中打开了一个打印框

问题是,当它打开时,它似乎在控制器存储字段之前弹出。所有字段都被存储,但在打印窗口中仍显示更新前的值。

我需要确保数据库已更新,然后调用打印票的页面?

我考虑过将它放在一边,if @ticket.save但您似乎无法渲染两次,即使用具有焦点的弹出窗口重定向到主应用程序屏幕。

关于如何最好地实现此功能的任何想法。目前它被击中和错过有时它在 /print/html.erb 中具有更新的值,而其他时候它具有预更新值,所以我认为它触发得太快,即在控制器中完成 .save 之前。

如果我$.print_page(15)从控制台调用,一切都像做梦一样。

还尝试setTimeout()以 2 秒的延迟包装 a ,但这根​​本不会从 onclick 事件中触发,而是手动从控制台获取文件 ???

任何帮助表示赞赏

4

0 回答 0