嗨,我对React很新,并且非常难以绕过整个状态管理并通过状态和道具传递数据.我确实理解标准的反应方式是以单向方式传递数据 - 从父节点到子节点,我已经为所有其他组件这样做了.但我有一个名为Book的组件,它根据用户选择形式'read,wantToRead,currentReading和none'改变其"shelf"状态.在我的BookList组件中呈现Book组件,但它需要能够读取Book的架子状态并在名为'read,wantToRead,currentReading和none'的部分下呈现正确的书籍.而且由于在这种情况下,Book组件是从BookList组件呈现的,而BookList是父组件,我真的无法理解如何启用BookList来访问Book的状态?BookList组件:
import React, { Component } from 'react'
import { Link } from 'react-router-dom'
import Book from './Book'
class BookList extends Component {
render(){
const { books, shelf } = this.props
return (
<div className="list-books">
<div className="list-books-content">
<div className="list-books-title">
<h1>MyReads</h1>
</div>
<div className="bookshelf">
<h2 className="bookshelf-title">None</h2>
{books.map((book)=> {
console.log(book)
if (shelf === ''){
return <div className="bookshelf-books">
{/* <BookStateless book= {book} /> */}
<Book book = {book} />
{/* <BookStateless book= {book} /> */}
</div>
}
})}
</div>
<div className="bookshelf"> …Run Code Online (Sandbox Code Playgroud) 我正在使用 jquery 使用户能够单击按钮来复制折扣代码。由于某种原因,document.execCommand("Copy");根本不起作用。当我ctrl + v粘贴时,什么也没有复制过来。有人可以帮我吗?谢谢!!
$(document).ready(function(){
$('#copyBtn').click(function(){
console.log("loaded")
var copyText = $('#discountCode');
console.log($('#discountCode').text())
copyText.select();
document.execCommand("Copy");
alert("Copied the text: " + copyText.text());
})
});Run Code Online (Sandbox Code Playgroud)
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.2.3/jquery.min.js"></script>
<p>Receive 20% discount on registration fees using the code: <strong><span id="discountCode">FKR2455EMSPN</span></strong></p>
<p>
To register, you will be taken to the
SuperReturn website.
</p>
<p>
Click <button id="copyBtn">here </button> to copy our VIP code to your clipboard
</p>
<p>
Click <a href='#'>
here</a> to now be taken to the SuperReturn registration page. …Run Code Online (Sandbox Code Playgroud)