Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Taro 没有createElement 等这些 api ,要进行 JSX 拼接怎么处理? #1220

Closed
JoMartinezZhu opened this issue Nov 23, 2018 · 2 comments
Labels
question Further information is requested

Comments

@JoMartinezZhu
Copy link

问题描述
Taro 没有createElement 等这些 api ,要进行 JSX 拼接怎么处理?

期望:

const arr1=['1','3','5']
const arr2=['2','4']
render(){
return(
1    <Text className="color">2</Text>  3    <Text className="color">4</Text>    5
);
}

系统信息

  • 操作系统: [e.g.mac ]
  • Taro 版本 [e.g. v.1.0.7]
  • Node.js 版本 [e.g. v11]
  • 报错平台 [ weapp]
@taro-bot
Copy link

taro-bot bot commented Nov 23, 2018

欢迎提交 Issue~

如果你提交的是 bug 报告,请务必遵循 Issue 模板的规范,尽量用简洁的语言描述你的问题,最好能提供一个稳定简单的复现。🙏🙏🙏

如果你的信息提供过于模糊或不足,或者已经其他 issue 已经存在相关内容,你的 issue 有可能会被关闭。

Good luck and happy coding~

@yuche
Copy link
Contributor

yuche commented Nov 23, 2018

JSX 的语法就是 createElement 的语法糖,除了重新封装 createElement 函数之外的行为,理论上 createElement 能做到的事情 JSX 都能做到。JSX 是声明式的风格,createElement 是命令式的风格,只要你习惯声明式的风格就好了。

你现在给出的例子是一个不合法的语法,这个 babel 直接会给报错。如果把这段代码放到一个 JSX 元素的 children 里倒是可行,但也不好写。原因其实不是因为没有 createElement,而是因为 Taro 现在用的是 babel 6, 没法支持 fragment 返回一个数组。

但代码是死的,人是活的。 你可以更改你的数据源数据结构,也可以更改你 JSX 的标签结构做到同样的事情。

@yuche yuche added the question Further information is requested label Nov 23, 2018
@yuche yuche added the resolved label Nov 26, 2018
@yuche yuche closed this as completed Nov 26, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants