我是新的反应,我试图从js文件导入一个对象列表,并将它们设置为我的应用程序的初始状态,如下所示:
import allSamples from './reducers/reducerSamples';
var App = React.createClass({
getInitialState () {
return {
samples:{allSamples},
}
},
render () {
...
这是我的带有对象的js文件:
var allSamples = [
{
id:"1",
sampleName:'Deep House Base',
sampleFamily:'Deep House Pack',
parentCategory:"bass",
subCategory:"house bass",
uploader:"Ben",
soundSource:"../../samplesWav/bd_909dwsd.wav",
tags:[
"house","ghouse","tech-house","rad"
]
},
{
id:"2",
sampleName:'Deep House Base',
sampleFamily:'Deep House Pack',
parentCategory:"bass",
subCategory:"house bass",
uploader:"Ben",
soundSource:"../../samplesWav/bd_chicago.wav",
tags:[
"house","ghouse","tech-house","rad"
]
},
{
id:"3",
sampleName:'Deep House Base',
sampleFamily:'Deep House Pack',
parentCategory:"bass",
subCategory:"house bass",
uploader:"Ben",
soundSource:"../../samplesWav/bd_dandans.wav",
tags:[
"house","ghouse","tech-house","rad"
]
},
{
id:"4",
sampleName:'Deep House Base',
sampleFamily:'Deep House Pack',
parentCategory:"bass",
subCategory:"house bass",
uploader:"Ben",
soundSource:"../../samplesWav/bd_deephouser.wav",
tags:[
"house","ghouse","tech-house","rad"
]
},
{
id:"5",
sampleName:'Deep House Base',
sampleFamily:'Deep House Pack',
parentCategory:"bass",
subCategory:"house bass",
uploader:"Ben",
soundSource:"../../samplesWav/bd_diesel.wav",
tags:[
"house","ghouse","tech-house","rad"
]
},
{
id:"6",
sampleName:'Deep House Base',
sampleFamily:'Deep House Pack',
parentCategory:"bass",
subCategory:"house bass",
uploader:"Ben",
soundSource:"../../samplesWav/bd_dropped.wav",
tags:[
"house","ghouse","tech-house","rad"
]
}
]
React dev工具中的状态表示"空对象",我没有正确导入文件?找不到其他有类似问题的人
答案 0 :(得分:0)
这里可以发生的一些事情:
尝试console.log(allSamples);
以上var App ..
以确保您正确地将其拉出来。
确保您的转换器支持{ samples: {allSamples} }
语法。或者只是说{ samples: allSamples }
,看看是否有效。