0

使用 Oraclejet 框架,我试图制作一个只有 2 个选项的拆分按钮。我怎样才能区分它们,以便每个都有自己的功能?或者如何粘贴 selected 的文本作为参数?

是这样的

<div id="dialogWrapper" style="position:relative; max-height:1%; max-width:1%;">
 <button id="printPdf" style="margin-right:6px;"data-bind="
                        ojComponent: {component: 'ojButton',            
                                      menu:'#choices'
                                      }"/>

里面的菜单:

 <ul id="choices" style="display:none"
      data-bind="ojComponent: {component: 'ojMenu', select: print//here both of them call to same function}">
 <li id="PDF">
         a href="#"><span class=""></span>PDF</a>
        </li>
        <li id="Excel">
        <a href="#"><span class=""></span>Excel</a>
     </li>     
  </ul> 
 </div> 
4

1 回答 1

2

这是通过使用选择处理函数的一些参数来完成的:

我重新创建了上面的示例并测试了这段代码:

<div id="dialogWrapper" style="position:relative; max-height:1%; max-width:1%;">
 <button id="printPdf" style="margin-right:6px;"data-bind="
                        ojComponent: {component: 'ojButton',            
                                      menu:'#printOptionsList',
                                      label: 'Print Option'
                                      }"/>
 <ul id="printOptionsList" style="display:none"
      data-bind="ojComponent: {component: 'ojMenu', select:printOptionHandler}">
 <li id="selPdf"><a href="#"><span class="oj-menu-item"></span>PDF</a></li>
 <li id="selExcel"><a href="#"><span class="oj-menu-item"></span>Excel</a>
     </li>     
  </ul> 
 </div> 

至于脚本部分,我已将 printOptionHandler 添加到主要的淘汰对象:

self.printOptionHandler = function(event,ui){
            var sel = ui.item.children("a").text();
            //alert('option selected: ' + sel);
            if (sel == "Excel") {
                alert("calling Excel function");
            } else if (sel == "PDF"){
                alert ("calling PDF function");
            }
        };

这是否也会为您提供所需的输出?

于 2016-08-01T15:25:34.397 回答