【问题标题】:AlloyUI modal reuse modalAlloyUI 模态复用模态
【发布时间】:2015-01-13 19:56:39
【问题描述】:

我正在开发一个 AlloyUI 模式窗口,该窗口出现在我的应用程序的许多页面中。 modal结构其实是一样的,唯一不同的是每个页面的bodyContent文本。我正在尝试重用 AlloyUI 模态脚本,只更新 bodyContent 参数,而不是为每个页面创建 20 个模态脚本,但这对我来说是脚本噩梦,因为我没有找到任何可以查看的代码。我创建了一个 jsfiddle 作为示例,下面是我一直在工作的脚本。非常感谢您的帮助。

http://jsfiddle.net/x9t3q0bs/

YUI().use('aui-modal', function(Y) {

  var helpModConfIdent              = Y.one('#showHelpPageConfirmIdentification'),
      helpModQuestions              = Y.one('#showHelpPageQuestions'),
      helpPageConfirmIdentRetCust   = Y.one('#showHelpPageConfirmIdentRetCust')


  var modal = new Y.Modal({
    bodyContent: "<p>Here will show help modal1.</p>",
    centered: true,
    destroyOnHide: false,
    headerContent: '<h3>Help info</h3>',
    modal: true,
    render: '#modal',
    visible: false,
    width: 800, 
    toolbars: {
    }
  });



modal.addToolbar([{
    label: 'Close',
    cssClass: 'btn-primary-content',
    on: {
      click: function() {
        modal.hide();
      }
    }
  }]);

  modal2 = new Y.Modal(
      {
      bodyContent: "<p>Here will show help modal2.</p>",
        centered: true,
        destroyOnHide: false,
        headerContent: '<h3>Help info</h3>',
        modal: true,
        render: '#modal',
        visible: false,
        width: 800, 
        toolbars: {
        }
      }
    );





      if (helpModConfIdent) {
        helpModConfIdent.on('click', function (e) {
          modal.show();
        });
      } else if (helpModQuestions) {
        helpModQuestions.on('click', function (e) {
          modal2.show();
        });
      }

});

谢谢

【问题讨论】:

    标签: javascript twitter-bootstrap modal-dialog yui alloy-ui


    【解决方案1】:

    bodyContentset 可用的属性之一,如果您有权访问模态实例。否则,您始终可以在已呈现的模板中操作 html。

    YUI().use('aui-modal', function(Y) {
     
     var modal = new Y.Modal({
        bodyContent: "<p>Default implementation</p>",
        centered: false,
        destroyOnHide: false,
        headerContent: '<h3>Help info</h3>',
        modal: true,
        render: '#modal',
        visible: false,
        width: 250
      });
          
          Y.one('#modalInstance').on('click', function(){
                 modal.set('bodyContent', "<p>Something loaded using the orginal modal instance</p>")
                 modal.show()
               }) 
       
          Y.one('#nodeInstance').on('click', function (e) {    
               Y.one('#modal .modal-content .modal-body').setHTML('<p>Set using the node instance</p>')
               modal.show()
            })
     
    });
    <script src="http://cdn.alloyui.com/3.0.0/aui/aui-min.js"></script>
    <link href="http://cdn.alloyui.com/3.0.0/aui-css/css/bootstrap.min.css" rel="stylesheet"></link>
    
     
    <div id='modalInstance'>Modal Instance</div>
    <br/>
    <div id='nodeInstance'>Node Instance</div>
    
    <div class="yui3-skin-sam">
      <div id="modal"></div>
    </div>

    【讨论】:

    • 非常感谢 Origineil。这对我很有帮助。
    • 顺便说一句,也许您可​​以对有关表单验证的另一个alloyUI/yui 问题有所了解。我在这里发布了另一个问题:stackoverflow.com/questions/27953713/yui-input-group-validation
    • 您能否告诉我们如何从创建的模式中动态添加或删除按钮。谢谢。
    • 好的。我访问了您的 jsfiddle 页面,发现了 addtoolbar 方法。我认为它会起作用。虽然我无法运行那个 jsfiddle 页面。不知道怎么运行。
    • @muasif80 OP 中的小提琴没有工作所需的所有 html。是的,addToolbar 是一种控制模式中出现的控制元素的方法。 Official Documentation Example
    猜你喜欢
    • 2015-09-26
    • 1970-01-01
    • 2017-01-29
    • 2016-07-24
    • 2020-04-07
    • 1970-01-01
    • 2017-01-28
    • 2016-06-29
    • 1970-01-01
    相关资源
    最近更新 更多