Meteor:使用Jquery创建对话框

Meteor: Using Jquery for creating dialog

本文关键字:创建 对话框 Jquery 使用 Meteor      更新时间:2023-09-26

我使用jquery在web应用程序中创建对话框。在正常的应用程序中,我可以使用jquery轻松地完成这项任务。但当移动到Meteor时,Meteor似乎改变了许多正常javascript无法工作的事情。这是我的代码:

<template name="post_list">
    <button id="ask_question_btn">Ask A Question</button>
    <div id="dialog" title="Dialog Title goes here...">Custom Dialog</div>
</template>

这里是相应的javascript:

Template.post_list.events({
    'click #ask_question_btn': function(event, template) {
        template.$( "#dialog" ).dialog( "open" );
    }
});

当我跑步的时候,没有任何东西显示出来。我不知道如何调试这个。请帮我解决这个问题。

感谢:)

我不认为$.dialog()函数是jQuery的原生函数。我熟悉jQuery UI对话框功能,您可以通过包含Atmosphere中的任何jQuery UI包将其包含在应用程序中。

此外,在您的代码中,您需要在打开之前初始化对话框。我能够获得以下内容来使用mizzao:jquery ui包:

meteor add mizzao:jquery-ui

然后,在我的助手文件中:

Template.post_list.rendered = function() { // initialize the dialog once rendered
  $( "#dialog" ).dialog({autoOpen: false}); // autoOpen = false means this won't open until we ask it to
}
Template.post_list.events({
  'click #ask_question_btn': function(event, template) {
    $( "#dialog" ).dialog('open');
  }
});

希望对你有用。如果你有任何问题,请告诉我,我很乐意帮忙。