我正在使用reactjs,并且在尝试显示json数据时(无论是来自文件还是服务器)似乎无法阻止此错误:
Uncaught TypeError: this.props.data.map is not a function
Run Code Online (Sandbox Code Playgroud)
我看过:
抛出"TypeError:this.props.data.map不是函数"的反应代码
React.js this.props.data.map()不是函数
这些都没有帮助我解决问题.在我的页面加载之后,我可以验证this.data.props没有未定义(并且确实有一个等价于json对象的值 - 可以调用window.foo),所以看起来它没有及时加载它被调用时ConversationList.如何确保该map方法正在处理json数据而不是undefined变量?
var converter = new Showdown.converter();
var Conversation = React.createClass({
render: function() {
var rawMarkup = converter.makeHtml(this.props.children.toString());
return (
<div className="conversation panel panel-default">
<div className="panel-heading">
<h3 className="panel-title">
{this.props.id}
{this.props.last_message_snippet}
{this.props.other_user_id}
</h3>
</div>
<div className="panel-body">
<span dangerouslySetInnerHTML={{__html: rawMarkup}} />
</div>
</div>
);
}
});
var ConversationList = React.createClass({
render: function() {
window.foo = this.props.data;
var conversationNodes = this.props.data.map(function(conversation, index) {
return …Run Code Online (Sandbox Code Playgroud) 我读了几个关于相同的旧线程,但看到文件API最近发生了很大的变化.我的要求是保存一个json文件(数据在indexdDB本地,但我需要一种备份方式).由于我使用indexdDB,我只针对最近的浏览器,主要是chrome.那么,是否可以将数据(json字符串)保存到客户端计算机?
我见过http://eligrey.com/demos/FileSaver.js/,但有没有办法本地做到这一点?
谢谢.