react+bootstrap实现一个简洁的待办事宜todo效果代码
代码语言:html
所属分类:表单美化
代码描述:react+bootstrap实现一个简洁的待办事宜todo效果代码
下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开
<!DOCTYPE html> <html lang="en" > <head> <meta charset="UTF-8"> <link type="text/css" rel="stylesheet" href="//repo.bfw.wiki/bfwrepo/css/bootstrap.3.3.4.css"> <style> .vert-offset-top-0{ margin-top: 0em; } #todoBox{ margin-top:40px; } </style> </head> <body > <section class="container vert-offset-top-2"> <div id="todoBox" class="todoBox "></div> </section> <script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/babel.min.js"></script> <script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/react-0.13.0.min.js"></script> <script type = "text/babel"> var TodoBox = React.createClass({ getInitialState: function () { return { data: [ {"id":"00001","task":"Wake up","complete":"false"}, {"id":"00002","task":"Eat breakfast","complete":"false"}, {"id":"00003","task":"Go to work","complete":"false"} ] }; }, generateId: function () { return Math.floor(Math.random()*90000) + 10000; }, handleNodeRemoval: function (nodeId) { var data = this.state.data; data = data.filter(function (el) { return el.id !== nodeId; }); this.setState({data}); return; }, handleSubmit: function (task) { var data = this.state.data; var id = this.generateId().toString(); var complete = 'false'; data = data.concat([{id, task, complete}]); this.setState({data}); }, handleToggleComplete: function (nodeId) { var data = this.state.data; for (var i in data) { if (data[i].id == nodeId) { data[i].complete = data[i].complete === 'true' ? 'false' : 'true'; break; } } this.setState({data}); return; }, render: function() { return ( <div className="well"> <h1 className="vert-offset-top-0">To do:</h1> <TodoList data={this.state.data} removeNode={this.handleNodeRemoval} toggleComplete={this.handleToggleComplete} /> <TodoForm onTaskSubmit={this.handleSubmit} /> </div> ); } }); var TodoList = React.createClass({ removeNode: function (nodeId) { this.props.removeNode(nodeId); return; }, toggleComplete: function (nodeId) { this.props.toggleComplete(nodeId); return; }, render: function() { var listNodes = this.props.data.map(function (listItem) { .........完整代码请登录后点击上方下载按钮下载查看
网友评论0