从 IndexedDB 中拉取数据到数组中并通过 ReactJS 输出
Pull data from IndexedDB into array and output it via ReactJS
我的实际 Javascript 代码如下:
var schoolsData = new Array();
myDB.schools
.each(function(school) {
console.log('"' + school.title + '" wird auf den Array gepusht.');
schoolsData.push(new Array(school.title, schools.schoolnumber, school.address, school.principal, school.email, school.creationdate, school.lastupdate, school.comment));
});
var SchoolsRender = React.createClass({
render: function() {
return (
<tr>
{this.props.list.map(function(listValue){
return <td>{listValue}</td>;
})}
</tr>
)
}
});
ReactDOM.render(<SchoolsRender list={schoolsData} />, document.getElementById('schoolsDATA'));
如您所见,我正在尝试从我的本地 IndexedDB 数据库中提取数据(我正在使用 dexieJS)并通过 ReactJS 将其放入 table 元素中,但没有出现任何内容。重点在哪里?
编辑:我认为问题基本上是我正在尝试输出该 3D 数组。有什么简单优雅的解决方案吗?
添加另一个组件 RowRender 以呈现单行。相应地修改 SchoolsRender 组件。
var RowRender = React.createClass({
render: function() {
return (
<tr>
<td>{this.props.title}</td>
<td>{this.props.schoolnumber}</td>
<td>{this.props.address}</td>
<td>{this.props.principal}</td>
</tr>
)
}
});
var SchoolsRender = React.createClass({
render: function() {
return (
<table>
{this.props.list.map(function(listValue,index){
return <RowRender key={index} title={listValue.title} schoolnumber={listValue.schoolnumber} address={listValue.address} title={listValue.address} />;
})}
</table>
)
}
});
我的实际 Javascript 代码如下:
var schoolsData = new Array();
myDB.schools
.each(function(school) {
console.log('"' + school.title + '" wird auf den Array gepusht.');
schoolsData.push(new Array(school.title, schools.schoolnumber, school.address, school.principal, school.email, school.creationdate, school.lastupdate, school.comment));
});
var SchoolsRender = React.createClass({
render: function() {
return (
<tr>
{this.props.list.map(function(listValue){
return <td>{listValue}</td>;
})}
</tr>
)
}
});
ReactDOM.render(<SchoolsRender list={schoolsData} />, document.getElementById('schoolsDATA'));
如您所见,我正在尝试从我的本地 IndexedDB 数据库中提取数据(我正在使用 dexieJS)并通过 ReactJS 将其放入 table 元素中,但没有出现任何内容。重点在哪里?
编辑:我认为问题基本上是我正在尝试输出该 3D 数组。有什么简单优雅的解决方案吗?
添加另一个组件 RowRender 以呈现单行。相应地修改 SchoolsRender 组件。
var RowRender = React.createClass({
render: function() {
return (
<tr>
<td>{this.props.title}</td>
<td>{this.props.schoolnumber}</td>
<td>{this.props.address}</td>
<td>{this.props.principal}</td>
</tr>
)
}
});
var SchoolsRender = React.createClass({
render: function() {
return (
<table>
{this.props.list.map(function(listValue,index){
return <RowRender key={index} title={listValue.title} schoolnumber={listValue.schoolnumber} address={listValue.address} title={listValue.address} />;
})}
</table>
)
}
});