2016-12-29 52 views
1

我有一個叫做this.fullscreen的函數,它需要知道它引用了什麼函數,我現在用this.refs這樣做,但是應該有一種更簡單的方式來訪問當前元素?傳遞當前DOM元素時是否需要使用ref?

<div ref='thumbs' style={{ 
     display: 'flex', 
     paddingTop: '20px', 
     ...this.fullscreen(this.refs.thumbs, 0.208, 0.772) 
    }}> 

回答

0

利用.bind(this)

<div ref='thumbs' style={{ 
    display: 'flex', 
    paddingTop: '20px', 
    ...this.fullscreen.bind(this, 0.208, 0.772) 
}}> 
+0

如果我需要原來這個對象forexample訪問狀態,可我得到的,不知怎的? – Himmators

+0

這根本不起作用,我嘗試過''和'fullscreen2(){console.log('test')}'但它沒有得到觸發。 – Himmators

相關問題