在我的Express中,我设置了这样的路由器,以便在服务器端呈现组件app.get('/dashboard', auth.isLoggedIn, function(req, res) {
quotes.findAllByUser(req.user.id).then(function(result){
var Dashboard=require('../component/dashboard.js').Dashboard;
var DashboardHTML=ReactDOMServer.renderToString(
<Dashboard user={req.user} list={result}/>
);
res.render('dashboard.ejs',{dashboard:DashboardHTML});
});
});
:
Dashboard
在我的组件var React=require('react');
var CreateFragment=require('react-addons-create-fragment');
var Dashboard=React.createClass({
render:function(){
var children=CreateFragment({
childUser:this.props.user,
childList:this.props.list
});
return (
<div classNameN="container">
{children.childUser}
</div>
);
}
});
exports.Dashboard=Dashboard;
中,用React这样编写:
Unhandled rejection Invariant Violation: Objects are not valid as a React child (found: object with keys {avatar, email, id, name, token, type}). If you meant to render a collection of children, use an array instead or wrap the object using createFragment(object) from the React add-ons. Check the render method of `Dashboard`.
然后我启动了服务器并在该路由中输入了浏览器,并收到此错误:
console.log(this.props)
如果我在返回render
函数之前尝试props
,则所有对象都会正常登录到控制台。但我无法渲染它。我以为我已经用片段
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/topspacer"
android:layout_width="wrap_content"
android:layout_height="wrap_content" android:text=" "/>
<TextView
android:id="@+id/name"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/aisle"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/subaisle"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/typee"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/price"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/bottomspacer"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=" "/>