diff options
author | afc163 <afc163@gmail.com> | 2016-11-11 12:10:26 +0800 |
---|---|---|
committer | afc163 <afc163@gmail.com> | 2016-11-11 12:10:26 +0800 |
commit | 614f6c90232d890984d0f4f2f13ff41fdb144b27 (patch) | |
tree | ce1a9be06b3264fd9fc09b3c2b028646db03a322 /examples/value-and-defaultValue.js | |
parent | cb5a445c75c7117c7c705d615099086274c2b254 (diff) | |
parent | f429b4a79df25c9eadc3901e2483716835cc7de7 (diff) | |
download | time-picker-614f6c90232d890984d0f4f2f13ff41fdb144b27.tar.gz time-picker-614f6c90232d890984d0f4f2f13ff41fdb144b27.tar.zst time-picker-614f6c90232d890984d0f4f2f13ff41fdb144b27.zip |
Merge branch 'master' of github.com:react-component/time-picker
Diffstat (limited to 'examples/value-and-defaultValue.js')
-rw-r--r-- | examples/value-and-defaultValue.js | 27 |
1 files changed, 11 insertions, 16 deletions
diff --git a/examples/value-and-defaultValue.js b/examples/value-and-defaultValue.js index 1be30cc..0e1aa14 100644 --- a/examples/value-and-defaultValue.js +++ b/examples/value-and-defaultValue.js | |||
@@ -4,25 +4,17 @@ import 'rc-time-picker/assets/index.less'; | |||
4 | 4 | ||
5 | import React from 'react'; | 5 | import React from 'react'; |
6 | import ReactDom from 'react-dom'; | 6 | import ReactDom from 'react-dom'; |
7 | 7 | import moment from 'moment'; | |
8 | import GregorianCalendar from 'gregorian-calendar'; | ||
9 | import DateTimeFormat from 'gregorian-calendar-format'; | ||
10 | import TimePicker from 'rc-time-picker'; | 8 | import TimePicker from 'rc-time-picker'; |
11 | import TimePickerLocale from 'rc-time-picker/src/locale/zh_CN'; | ||
12 | |||
13 | const formatter = new DateTimeFormat('HH:mm:ss'); | ||
14 | |||
15 | const now = new GregorianCalendar(TimePickerLocale.calendar); | ||
16 | now.setTime(Date.now()); | ||
17 | 9 | ||
18 | const App = React.createClass({ | 10 | const App = React.createClass({ |
19 | getInitialState() { | 11 | getInitialState() { |
20 | return { | 12 | return { |
21 | value: now, | 13 | value: moment(), |
22 | }; | 14 | }; |
23 | }, | 15 | }, |
24 | handleValueChange(value) { | 16 | handleValueChange(value) { |
25 | console.log(value && formatter.format(value)); | 17 | console.log(value && value.format('HH:mm:ss')); |
26 | this.setState({ value }); | 18 | this.setState({ value }); |
27 | }, | 19 | }, |
28 | clear() { | 20 | clear() { |
@@ -33,11 +25,14 @@ const App = React.createClass({ | |||
33 | render() { | 25 | render() { |
34 | return ( | 26 | return ( |
35 | <div> | 27 | <div> |
36 | <TimePicker formatter={formatter} locale={TimePickerLocale} | 28 | <TimePicker |
37 | defaultValue={now} /> | 29 | defaultValue={this.state.value} |
38 | <TimePicker formatter={formatter} locale={TimePickerLocale} | 30 | onChange={this.handleValueChange} |
39 | value={this.state.value} | 31 | /> |
40 | onChange={this.handleValueChange}/> | 32 | <TimePicker |
33 | value={this.state.value} | ||
34 | onChange={this.handleValueChange} | ||
35 | /> | ||
41 | <button onClick={this.clear}>clear</button> | 36 | <button onClick={this.clear}>clear</button> |
42 | </div> | 37 | </div> |
43 | ); | 38 | ); |