Pull data from IndexedDB into array and output it via ReactJS

我的未来我决定 提交于 2019-12-08 04:30:36

问题


My actual Javascript code is the following:

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'));

As you can see I am trying to pull data from my local IndexedDB database (I am using dexieJS) and put it via ReactJS into a table element but nothing appears. Where is the point?

Edit: I think the problem is basically that I'm trying to output that 3D array. Is there any simple and elegant solution?


回答1:


Add another component RowRender to render single row. Modify SchoolsRender component accordingly.

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>
        )
    }
});


来源:https://stackoverflow.com/questions/37273721/pull-data-from-indexeddb-into-array-and-output-it-via-reactjs

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!