我有一个样式按钮:
import { Link } from 'react-router-dom'
import styled from 'styled-components'
const Button = styled(Link)`
display: block;
border: 1px solid white;
padding: 5px;
`
Run Code Online (Sandbox Code Playgroud)
我可以将它用作Link:
<Button to='/' />
Run Code Online (Sandbox Code Playgroud)
但有时我想将其用作a:
<Button as='a' href='/' />
Run Code Online (Sandbox Code Playgroud)
但在第二种情况下,TypeScript 抱怨:
Type '{ children: string; as: string; href: string; }' is not assignable to type 'Readonly<ThemedOuterStyledProps<WithOptionalTheme<LinkProps, any>, any>>'.
Property 'to' is missing in type '{ children: string; as: string; href: string; }'.
Run Code Online (Sandbox Code Playgroud)
我有一个看起来像这样的哈希:
h = {
a: [ ["c", "1"],["d","2"],["e","3"],["f","4"] ],
b: [ ["g","5"],["h","6"],["i","7"],["j","8"] ],
c: [ ["k","9"],["l","10"],["m","11"],["n","12"] ]
}
Run Code Online (Sandbox Code Playgroud)
从中提取数字的最佳方法是什么,所以它看起来像这样?
[1,2,3,4,5,6,7,8,9,10,11,12]
Run Code Online (Sandbox Code Playgroud)
我尝试了一些不同的东西,但它总是需要一个外部数组,我必须从一系列each命令进入.
我已经修改了react-dnd 可排序示例,以便在我的应用程序中使用.
我不能让"不透明"跟随我的拖累.
当我最初选择元素时,应用了不透明度:
但是当我向上移动以改变位置时,不透明度仍然应用于原始DOM元素(?).
状态相应地更改,与此状态关联的表中的列正在重新排序.因此,除了不透明之外,其他一切都很好.
当我移动元素时,只有li的值被改变但是data-reactid没有改变位置.
我的应用程序的唯一区别是我如何管理状态.在我的应用程序中,状态通过redux进行管理.
将hover被传递给该DropTarget的功能基本上是从示例复制和粘贴.
SortableColumnEntry组件:
class SortableColumnEntry extends Component {
render(){
const { connectDragSource, connectDropTarget } = this.props
const { column, isDragging, index } = this.props
const opacity = isDragging ? 0 : 1
const element = connectDropTarget(connectDragSource(
<li
style={{opacity: opacity}}</li>
))
return element
}
}
export default flow(
DragSource(DragTypes.COLUMN, source, (connect, monitor) => ({
connectDragSource: connect.dragSource(),
isDragging: monitor.isDragging()
})),
DropTarget(DragTypes.COLUMN, target, (connect) => ({
connectDropTarget: connect.dropTarget()
}))
)(SortableColumnEntry)
Run Code Online (Sandbox Code Playgroud) 我有一个班级学生和动态创建的学生阵列:
class Student{
public:
void create(){
system("cls");
cout << "First name: ";
cin >> fn;
cout << "Last name: ";
cin >> ln;
cout << "How many subjects? ";
cin >> sub_number;
subjects = new string[sub_number];
for(int i = 0; i < sub_number; i++){
cout << "Subject name: ";
cin >> subject[i];
}
}
//This just display the student with a bunch of couts
friend ostream& operator<<(ostream&, const Student&);
~Student(){ delete[] subjects; }
private:
string fn;
string ln;
string* subjects; …Run Code Online (Sandbox Code Playgroud)