2016-04-07 148 views
2

我很难弄清楚如何让这个下拉实际工作。按钮呈现良好,但不会下降。关于我在这里失踪的任何想法?很确定我需要一个onClick函数,但不知道要控制它到下拉菜单。与reactjs和引导下拉菜单

var Dropdownbutton = React.createClass({ 
displayName: 'Dropdownbutton', 
render: function() { 
    return el.div(null, 
     el.div({className: 'col-xs-12 col-md-6 col-lg-3'}, 
     el.div({className:'btn-group'}, 
      el.a({href:'#',className:'btn btn-primary'},'Primary'), 
      el.a({href:'#',className:'btn btn-primary dropdown-toggle', "data-toggle":'dropdown'},el.span({className:'caret'},'')), 
      el.ul({className:'dropdown-menu'}, 
      el.li(null,el.a({href:'#'},'Action')), 
      el.li(null,el.a({href:'#'},'Another action')), 
      el.li(null,el.a({href:'#'},'Something else here')), 
      el.li({className:'divider'},''), 
      el.li(null,el.a({href:'#'},'Separated link')) 
     ) 
     ) 
    ) 
    ); 
} 

}); 
+1

您可能会发现[react-bootstrap](https://react-bootstrap.github.io/)非常有帮助。 – mjohnsonengr

+0

一直在反应-bootstrap,不知道我错过了什么。正常的按钮对我来说没有问题,但下拉式不想工作。 –

+0

你是对的,你需要一个onClick处理程序。 [此文件](https://github.com/react-bootstrap/react-bootstrap/blob/master/src/Dropdown.js)特别显示了react-bootstrap的方法。基本上,我相信onClick处理程序需要将open类添加到包含下拉列表(带有“btn-group”类的那个)的东西。对不起,我不能给你一个完整的例子。充其量我可以告诉你如何用react-bootstrap来做到这一点。 – mjohnsonengr

回答

0

从我可以推断出你没有带班下拉一个部门。稍微改变你的代码应该可以工作。

var Dropdownbutton = React.createClass({ 
displayName: 'Dropdownbutton', 
render: function() { 
    return el.div(null, 
     el.div({className: 'dropdown col-xs-12 col-md-6 col-lg-3'}, 
     el.div({className:'btn-group'}, 
      el.a({href:'#',className:'btn btn-primary'},'Primary'), 
      el.a({href:'#',className:'btn btn-primary dropdown-toggle', "data-toggle":'dropdown'},el.span({className:'caret'},'')), 
      el.ul({className:'dropdown-menu'}, 
      el.li(null,el.a({href:'#'},'Action')), 
      el.li(null,el.a({href:'#'},'Another action')), 
      el.li(null,el.a({href:'#'},'Something else here')), 
      el.li({className:'divider'},''), 
      el.li(null,el.a({href:'#'},'Separated link')) 
     ) 
     ) 
    ) 
    ); 
} 

});