MyList.js
2.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import React,{PropTypes} from 'react';
import ReactDom from 'react-dom'
import Member from './Member';
import cx from 'classnames';
import s from './MyList.scss';
class MyList extends React.Component {
constructor(props) {
super(props);
this.state={
}
}
render() {
const {itemRender,items}= this.props;
return <div scrollTop={300}>{items.map(itemRender)}</div>;
}
renderItem(item) {
var active = item.name === this.props.activeId;
var props = {
key: item.uuid,
item: item,
active: active
};
if (active) {
console.log(this.props.activeId);
props.ref = "activeItem";
}
let letter = 'A';
const {onChoose, onChange,choiceType}= this.props;
const key = item.uuid;
return( <div key={key} className={cx(s.letter_wrap)} {...props}>
{letter.length>0&&
<a key={key} name ={'#index#'+letter} id={'#index#'+letter}>
{letter}
</a>
}
<Member checked={false} myself={false}
imageUrl='http://localhost:3001//img/user.jpg' name={item.name} uuid={item.uuid} onClick={onChoose} onChange={onChange} choiceType={choiceType}/>
</div>);
// return <div {...props}> {item.name} </div>
}
componentDidUpdate(prevProps) {
// only scroll into view if the active item changed last render
console.log(this.props.activeId);
console.log(prevProps.activeId);
if (this.props.activeId != prevProps.activeId) {
this.ensureActiveItemVisible();
}
}
ensureActiveItemVisible() {
var itemComponent = this.refs.activeItem;
if (itemComponent) {
var domNode = ReactDom.findDOMNode(itemComponent);
console.log(domNode);
// this.scrollTop = domNode.offsetTop;
domNode.scrollIntoView(false);
//domNode.scrollTop();
// this.scrollElementIntoViewIfNeeded(domNode);
}
}
scrollElementIntoViewIfNeeded(domNode) {
var containerDomNode = ReactDom.findDOMNode(this);
// Determine if `domNode` fully fits inside `containerDomNode`.
// If not, set the container's scrollTop appropriately.
console.log(domNode.offsetTop);
//window.scrollTo(0, 300);
//containerDomNode.scrollTop = domNode.offsetTop;
}
}
export default MyList;