我有一個流星應用程序和React,其中我有一個名爲ChatManager
的組件。該組件導入我的chatrooms.js
API以發佈我的chatrooms
集合。它還會導入我的EditChatRoom
組件和我的ChatRoomRecord
組件。React + Meteor + Bootstrap Modal管理數據
基本上這裏是相關的代碼文件結構的摘要:
-imports
-api
-chatrooms.js
-ui
-chatmanager
-ChatRoomRecord.jsx
-EditChatRoom.jsx
ChatManager.jsx
我ChatRoomRecord
組件有一個onClick
功能,在記錄的點擊和chatroom
道具成功的作品。
我EditChatRoom
是modal
其中id="editChatRoomModal"
的ChatManager
部件是保持兩個ChatRoomRecord
和EditChatRoom
組件之一。
如何將chatroom
道具發送到EditChatRoom
組件?並且在旁註中,我如何使用React打開editChatRoomModal
?
非常感謝幫助!謝謝!
編輯:添加的信息
這裏是我的ChatManager
組件的基本表示:
class ChatManager extends Component {
renderChatRoomRecords() {
return this.props.chatrooms.map((chatroom) => (
<ChatRoomRecord key={chatrooom._id} chatroom={chatroom} />
))
}
render() {
return (
<div>
<EditChatRoom />
<table>
<tbody>
{this.renderChatRoomRecords()}
</tbody>
</table>
</div>
)
}
}
ChatManager.PropTypes = {
chatrooms: PropTypes.array.isRequired
}
export default createContainer(() => {
Meteor.subscribe('chatrooms')
return { chatrooms: ChatRooms.find({}).fetch() }
}, ChatManager)
那麼這裏就是我ChatRoomRecord
組件:
export class ChatRoomRecord extends Component {
constructor(props) {
super(props)
this.handleClick = this.handleClick.bind(this)
}
handleClick(event) {
event.preventDefault()
console.log("Click registered successfully: " + this.props.chatroom._id)
}
render() {
return (
<tr onClick{this.handleClick}>
{/* This code isn't relevant to the problem */}
</tr>
)
}
}
ChatRoomRecord.PropTypes = {
chatroom: PropTypes.object.isRequired
}
這工作巨星所以在映射中沒有問題點擊事件在註冊點擊的地方起作用,並顯示被點擊的chatroom._id
。
這裏是我的EditChatRoom
組件:
export class EditChatRoom extends Component {
render() {
return (
<div className="modal fade" id="editChatRoomModal" tabIndex="-1" role="dialog">
{/* This code isn't relevant to the problem */}
</div>
)
}
}
我需要打開這個模式,並通過被點擊我ChatRoomRecord
組件的chatroom
。
希望這能更好的解釋這個問題。
您可以將它作爲會話變量存儲嗎?然後用Session.get()獲取它。否則,還原。 –
Oooooh,是的,這是一個好主意,沒有想到這一點。這有助於數據方面的事情,現在我需要弄清楚在打開模式時應該怎麼做。 –
這給了我一個嘗試使用URL參數管理它的想法。所以我會盡量使用這些。 –