@Belinda
2015-05-18T07:39:14.000000Z
字数 2352
阅读 1147
翻译
prebuilt 预置
remainder 剩余
tag 标签
mandatory 强制性
modular 模块话
composable 可组成
components.成份
syntax 语法
optional 可选的
generating 生成
tenet 宗旨
frontends 前端
instantiates 实例化
injects 注入
raw 原
开始学习把
For this tutorial, we'll use prebuilt JavaScript files on a CDN. Open up your favorite editor and create a new HTML document:
在这个学习教程中,我们将会预置 javascript 文件。打开你最喜欢的编译器,创造一个新的 HTML 文档
For the remainder of this tutorial, we'll be writing our JavaScript code in this script tag.
本教程的剩余部分,我们将在脚本标签中写我们的 javascript 代码。
Note:
We included jQuery here because we want to simplify the code of our future ajax calls, but it's NOT mandatory for React to work.
说明:
我们包含了JQuery,因为我们想简化未来的ajax交互代码,而不是强制性的用react 去实现这些功能。
Your first component
React is all about modular, composable components. For our comment box example, we'll have the following component structure:
你的第一个组件
React 内容包括模块化,可组合的组件,拿我们的评论盒子做个例子,我们看看下面的组件结构
- CommentBox
- CommentList
- Comment
- CommentForm
Let's build the CommentBox component, which is just a simple
Note that native HTML element names start with a lowercase letter, while custom React classes names begin with an uppercase letter.
说明了native 的 HTML 结点,命名都是以一个小写字母开始,但客户端的React 类命名以大写字母开始。
The first thing you'll notice is the XML-ish syntax in your JavaScript. We have a simple precompiler that translates the syntactic sugar to this plain JavaScript:
你注意到的第一件是是 XML-ish 语法在你的javascript 代码中,有一个简单的程序,将这一纯JavaScript语法糖转化为原码的javascript:
Its use is optional but we've found JSX syntax easier to use than plain JavaScript。
它的使用是可选的,但我们发现JSX语法比纯JavaScript更容易使用
We pass some methods in a JavaScript object to React.createClass() to create a new React component.
我们通过一些方法,在react中使用createclass()创建一个新的 React 元件。
The most important of these methods is called render which returns a tree of React components that will eventually render to HTML.
这些方法中最重要的是 reader ,返回一个react 组件树(最总会转化为 HTML)。
The <div> tags are not actual DOM nodes; they are instantiations of React div components.
这些div 标签不是真实的结点,他们是 react 组件的实例。
You can think of these as markers or pieces of data that React knows how to handle.
你可以把这些作为标志或数据块,React知道如何处理。
React is safe. We are not generating HTML strings so XSS protection is the default.
react 是安全的。我们不是生成的HTML字符串,XSS保护是默认的。
You do not have to return basic HTML. You can return a tree of components that you (or someone else) built. This is what makes React composable: a key tenet of maintainable frontends.
你不必返回基本的HTML。你可以返回一个,你(或其他人)建的组件树。
这就是什么使得React的可组合:可维护的前端的关键原则。
React.render() instantiates the root component, starts the framework, and injects the markup into a raw DOM element, provided as the second argument.
react.render(),实例化根组件,启动框架,并将标记为原始DOM元素,作为第二个参数。