在大多数情况下,拥有父标记不是问题.
React.createClass({
render: function() {
return (
<tbody>
<tr><td>Item 1</td></tr>
<tr><td>Item 2</td></tr>
</tbody>
);
}
});
Run Code Online (Sandbox Code Playgroud)
但是在某些情况下,在没有父项的情况下将兄弟元素放在一个渲染函数中是有意义的,特别是在表的情况下,您不希望在表中包装表行div.
React.createClass({
render: function() {
return (
<tr><td>Item 1</td></tr>
<tr><td>Item 2</td></tr>
);
}
});
Run Code Online (Sandbox Code Playgroud)
第二个示例给出以下错误:Adjacent XJS elements must be wrapped in an enclosing tag while parsing file.
如何渲染两个兄弟元素而不将它们包裹在<div>类似的东西中?
这是我的gulpfile.js
var gulp = require('gulp');
var browserify = require('browserify');
var source = require("vinyl-source-stream");
var reactify = require("reactify");
var watchify = require('watchify');
var gutil = require('gulp-util');
var paths = {
scripts: ['src/jsx/index.jsx']
};
gulp.task('browserify', function(){
var bundler = watchify(browserify('./src/jsx/index.jsx', watchify.args));
bundler.transform(reactify);
bundler.on('update', rebundle);
function rebundle() {
return bundler.bundle()
// log errors if they happen
.on('error', gutil.log.bind(gutil, 'Browserify Error'))
.pipe(source('bundle.js'))
.pipe(gulp.dest('./public/js'));
}
return rebundle();
});
gulp.task('watch', function() {
gulp.watch(paths.scripts, ['browserify']);
});
Run Code Online (Sandbox Code Playgroud)
然后我的命令行输出如下所示:
$ gulp watch
[15:10:41] Using gulpfile ~/blizztrack/dashboard/gulpfile.js
[15:10:41] Starting 'watch'... …Run Code Online (Sandbox Code Playgroud)