1
내 클래스에 CompondentDidMount를 추가하려고합니다.CompondentDidMount 실패 propType- fetch를 var로 정의하십시오.
실패하여 PropType : IndexRoute
에 공급 잘못된 소품 component
그러나, 이것은 오류를 반환합니다.
var PHOTODATA = [{ ... *json data* ... }]
...
var PhotoGallery = React.createClass({
getInitialState: function() {
return {
displayedCategories: []
};
},
...
render: function(){
var uniqueCategories = PHOTODATA.map(function (photo) {
return photo.tag; // tag is a list of tags...
}).reduce(function (uniqueList, someTags) {
return uniqueList.concat(
someTags.filter(function (thisTag) {
return !uniqueList.some(function(uniqueTag) {
return uniqueTag.id === thisTag.id && uniqueTag.taglevel === thisTag.taglevel
});
})
);
}, []
);
전체 코드는 다음에 수동으로이 같은 VAR로 내 JSON 데이터를 설정 한 경우
또한var PhotoGallery = React.createClass({
componentDidMount() {
return fetch("http://localhost:8000/api/test/?format=json")
.then((response) => response.json())
.then((json) => {
console.log(json);
this.setState({PHOTODATA: json})
})
},
getInitialState: function() {
return {
displayedCategories: []
};
},
, 내 코드가 잘 작동 : 여기
는 ComponentDidMount 이용할 수 있도록 시도 코드 :
http://codepen.io/yarnball/pen/GqbyWr?
당신이 우리에게 그 방법의 코드를 표시 할 수 있습니다 귀하의 구성 요소'PhotoGallery'를 수출하고 있다면 다른 구성 요소를 포함하고 있습니까? –
예 : 코드 http://codepen.io/yarnball/pen/GqbyWr? – Ycon