React学习——ListView(Reflux)
接前一篇,把前面的ListView改成Reflux的形式
var BookActions=Reflux.createActions([
'fetchList'
]);
var BookStore = Reflux.createStore({
listenables: [BookActions],
bookList:['item1','item2','item3'],
init:function () {
this.fetchList();
console.log('init done.');
},
fetchList:function(){
this.bookList.push('item'+(this.bookList.length+1));
console.log('fetchList'+this.bookList.length);
this.trigger(this.bookList);
}
}); var TextItem = React.createClass({
render:function(){
var item = this.props.item;
return <p>this is {item}</p>
}
}); var Template = React.createClass({
render:function(){
return React.createElement(this.props.type,this.props);
}
}); var ListViewItem = React.createClass({
render:function(){
var item = this.props.item;
var cls = this.props.isSelected?'selected':'';
if(this.props.template){
return <li className={cls} onClick={this.props.onClick}><Template type={this.props.template} item={item}></Template></li>;
}else{
return <li className={cls} onClick={this.props.onClick}>{item}</li>;
}
}
}); var ListView = React.createClass({
mixins: [Reflux.connect(BookStore, 'bookstore')],
onSelect:function(item){
this.setState({selectedItem:item});
console.log('selected item:' + item);
},
render: function() {
var itemTemplate = this.props.itemTemplate?this.props.itemTemplate:'';
var selectedItem = this.state.selectedItem;
console.log('state:' + this.state); for(var key in this.state){
console.log('key='+key);
} if(this.state.bookstore){
var items = this.state.bookstore?this.state.bookstore:[];
console.log('render items:' +this.state.bookstore + '-' + items.length);
return (
<ol>
{
items.map(function (item,i) {
var isSelected = (item ==selectedItem);
return <ListViewItem key={i} item={item} template={itemTemplate} isSelected={isSelected} onClick={this.onSelect.bind(this,item)}></ListViewItem>
},this)
}
</ol>
);
}else{
return <ol></ol>;
}
}
}); React.render(
<div>
<button onClick={BookActions.fetchList}>加一个</button>
<ListView itemTemplate={TextItem}>
</ListView>
</div> ,
document.body
); BookActions.fetchList();
React学习——ListView(Reflux)的更多相关文章
- React学习——ListView组件
(草稿) 先把代码放上来,再补充说明 <!DOCTYPE html> <html> <head> <title>React ListView</t ...
- React学习笔记-1-什么是react,react环境搭建以及第一个react实例
什么是react?react的官方网站:https://facebook.github.io/react/下图这个就是就是react的标志,非常巧合的是他和我们的github的编辑器Atom非常相似. ...
- react学习小结(生命周期- 实例化时期 - 存在期- 销毁时期)
react学习小结 本文是我学习react的阶段性小结,如果看官你是react资深玩家,那么还请就此打住移步他处,如果你想给一些建议和指导,那么还请轻拍~ 目前团队内对react的使用非常普遍,之 ...
- React学习资料
以下是我整理的React学习资料,包括:React基础.Redux.reat-router, redux middleware, higher order components, React验证等, ...
- React学习笔记(一) 基础知识
现在最热门的前端框架有AngularJS.React.Bootstrap等.自从接触了ReactJS,ReactJs的虚拟DOM(Virtual DOM)和组件化的开发深深的吸引了我. React的基 ...
- React学习系列
React学习系列 系列学习react 翻译地址 https://scotch.io/tutorials/learning-react-getting-started-and-concepts 我是初 ...
- react学习笔记1--基础知识
什么是react A JAVASCRIPT LIBRARY FOR BUILDING USER INTERFACES[React是一个用于构建用户界面的JavaScript库.] React之所以快, ...
- react 学习与使用记录
相关技术:webpack+react+react-router+redux+immutable 郭永峰react学习指南 1.git bash--windows命令行工具 --教程 下载地址 2. i ...
- 【JAVASCRIPT】React学习-JSX 语法
摘要 react 学习包括几个部分: 文本渲染 JSX 语法 组件化思想 数据流 JSX 语法 1. 定义 JSX 是javascript + xml 的合集,我们可以将javascript 与 ht ...
随机推荐
- logistic原理与实践
逻辑回归模型是一种将影响概率的不同因素结合在一起的指数模型,得到的是0~1之间的概率分布.自变量范围是,值域范围限制在0~1之间.在搜索广告.信息处理和生物统计中有广泛的应用.例如搜索广告的点击率预估 ...
- 【JAVA】【leetcode】【查找二叉树最小深度】
题目: minimum-depth-of-binary-tree 要求:Given a binary tree, find its minimum depth.The minimum depth i ...
- lamp搭建,thinkphp安装
有几天没有记录学习进度了,简单回顾一下:前天由于不熟悉linux的安装操作,以及遇上了各种问题花了将近6小时搭建好了lamp,然而在中途学习修改配置时误改了启动的图形文件,导致了昨天开机时图形界面无法 ...
- selenium移动div里面的滚动条,操作弹出对话框
还是使用js来移动 首先要定位到这个元素 倾向于使用js来定位元素,输入下面的脚本,按下回车键,即可在调试页面看到对应的div块$("div.table-responsive") ...
- 转载:《TypeScript 中文入门教程》
缘由 事情是这样的,我想搜索 TypeScript 中文教程,结果在 https://www.baidu.com , https://cn.bing.com ,上都找不到官方的翻译,也没有一个像样的翻 ...
- 面向对象的高级编程&IO编程
1.给类对象绑定的函数,只对这个对象生效, 而对类绑定的对象, 所有的对象都可以调用. 栗子: def set_score(self, score): self.score = score s.set ...
- [转]http-关于application/x-www-form-urlencoded等字符编码的解释说明
在Form元素的语法中,EncType表明提交数据的格式 用 Enctype 属性指定将数据回发到服务器时浏览器使用的编码类型. 下边是说明: application/x-www-form-urlen ...
- SQL Server系列
这里整理了我学习SQL Server的全部文章,包括从基础到高级,做一个目录,方便以后查找. SQL Server数据类型 SQL Server中开发常用的数据类型 单表查询和多表查询 一个单表查询的 ...
- 非Spring下的Quartz
转自:Nick Huang. http://www.cnblogs.com/nick-huang/ 阅读目录 > 参考的优秀资料 > 版本说明 > 简单的搭建 > 在We ...
- hadoop配置机架感知
接着上一篇来说.上篇说了hadoop网络拓扑的构成及其相应的网络位置转换方式,本篇主要讲通过两种方式来配置机架感知.一种是通过配置一个脚本来进行映射:另一种是通过实现DNSToSwitchMappin ...