React(JSX语法)-----JSX基本语法
JSX------HTML tags vs React Components:
1.To render a html tag,just use lower-case tag names in JSX;
var myDivElement = <div className="foo" />;
React.render(myDivElement, document.body);
2.To render a React Component,just create a local variable that starts with an upper-case latter;
var MyComponent = React.createClass({/*...*/});
var myElement = <MyComponent someProperty={true} />;
React.render(myElement, document.body);
JSX-------The Transform
React JSX transforms from an XML-like syntax into native JS xml elements,attributes and children are transformed into arguments to React.createElement
var Nav;
// Input (JSX):
var app = <Nav color="blue" />;
// Output (JS):
var app = React.createElement(Nav, {color:"blue"});
var Nav, Profile;
// Input (JSX):
var app = <Nav color="blue"><Profile>click</Profile></Nav>;
// Output (JS):
var app = React.createElement(
Nav,
{color:"blue"},
React.createElement(Profile, null, "click")
);
Javascript Expressions
1.Attribute Expressions:To use a JS expression as an attribute value,wrap the expression in a pair of curly braces({})instead of quotes("").
// Input (JSX):
var person = <Person name={window.isLoggedIn ? window.name : ''} />;
// Output (JS):
var person = React.createElement(
Person,
{name: window.isLoggedIn ? window.name : ''}
);
2.Child Expressions:Likewise,JS expressions may be used to express children:
/ Input (JSX):
var content = <Container>{window.isLoggedIn ? <Nav /> : <Login />}</Container>;
// Output (JS):
var content = React.createElement(
Container,
null,
window.isLoggedIn ? React.createElement(Nav) : React.createElement(Login)
);
3.Comments:it's easy to add comments within youe JSX,they are just JS expressions. you just need to bo careful to put {} around the comments when you are within the children sction of a tag.
var content = (
<Nav>
{/* child comment, put {} around */}
<Person
/* multi
line
comment */
name={window.isLoggedIn ? window.name : ''} // end of line comment
/>
</Nav>
);
最新文章
- from表单如果未指定action,submit提交时候会执行当前url
- [转]CIDR简介
- objective-c系列-NSMutableArray
- java判断request请求是手机还是pc终端
- HTML5基础
- MFC ADO连接Oracle12c数据库 客户端环境搭建
- graph | Max flow
- 常见设计模式解析和实现(C++)Adapt模式
- ssh连接超时问题解决方案
- java多线程安全问题-同步修饰符于函数
- Thinkphp 3.0-3.1版代码执行漏洞
- System.ComponentModel.DataAnnotations 冲突
- shell高级特性-4
- Ambari集成Kerberos报错汇总
- 服务器安装ubuntu 14.04 server,开机启动屏幕不停滚动错误WRITE SAME failed. Manually zeroing
- 量化交易-外汇交易-MetaTrader5
- SuperMap 二维地图和三维场景弹窗窗口大小控制
- 用actor model实现intel tbb这样的用法
- java代码------------条件运算符 ?:
- hdu 1130,hdu 1131(卡特兰数,大数)
热门文章
- SpringMVC-DispatcheServlet
- hibernate的1+n
- 扩展django的User的部分方法
- VS2010默认属性文件配置
- 学习Find函数和select
- 探索javascript----拖拽
- 遗传算法的C语言实现(一):以非线性函数求极值为例
- [Python Fabric] [SSH] Mac OS X 10.9 + Vagrant虚拟环境使用Python Fabric进行SSH远程登录的简单实验
- java 调用 sql server存储过程
- repo upload上传提交时发生remote rejected异常