2016-04-07 187 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')) 
     ) 
     ) 
    ) 
    ); 
} 

});