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 ...
随机推荐
- 面向对象的高级编程&IO编程
1.给类对象绑定的函数,只对这个对象生效, 而对类绑定的对象, 所有的对象都可以调用. 栗子: def set_score(self, score): self.score = score s.set ...
- Window.document对象
1.Window.document对象 一.找到元素: docunment.getElementById("id"):根据id找,最多找一个: var a =docunme ...
- MySql学习(三) —— 子查询(where、from、exists) 及 连接查询(left join、right join、inner join、union join)
注:该MySql系列博客仅为个人学习笔记. 同样的,使用goods表来练习子查询,表结构如下: 所有数据(cat_id与category.cat_id关联): 类别表: mingoods(连接查询时作 ...
- blade and soul Personal Combos
Personal Combos Since Blade and Soul is mainly based on skills, the game is more interesting after y ...
- 160个crackme-之Afkayas.1
工具: OD 环境: windows XP 运行: 我们先运行一下这个小程序,看看它到底是干什么的.运行后发现它要我们输入Type In your Name 和Type In your Serial ...
- ImageLoader1
package com.bawei.activity; import android.app.Activity; import android.graphics.Bitmap; import andr ...
- 更新证书错误:No matching provisioning profiles found
在Xcode中当你在更新了你得证书而再重新编译你的程序,真机调试会出现“Your build settings specify a provisioning profile with the UUID ...
- Python学习06——列表的操作(2)
笨办法学Python第39节 之前用的第三版的书,昨天发现内容不对,八块腹肌又给我下了第四版,这次的内容才对上.本节的代码如下: ten_things = "Apples Oranges C ...
- python学习04——列表的操作
笨办法学python第38节 如何创建列表在第32节,形式如下: 本节主要是讲对列表的操作,首先讲了 mystuff.append('hello') 的工作原理,我的理解是,首先Python找到mys ...
- Mysql VARCHAR的最大长度到底是多少
MySQL 数据库的varchar类型在4.1以下的版本中的最大长度限制为255,其数据范围可以是0~255或1~255(根据不同版本数据库来定).在 MySQL5.0以上的版本中,varchar数据 ...