0
に約束で使用SETSTATEがChromeでコードはここcomponentDidMount
componentDidMount: function() {
var self = this,
templates;
new Promise(function (resolve, reject) {
API.getTemplates(function (err, result) {
if (!err) {
templates = result.templates;
resolve();
}
});
}).then(function() {
return new Promise(function (resolve, reject) {
_.map(templates,function (template) {
console.log("template.companyId " +template.companyId);
API.getCompanyById(template.companyId, function (err, result) {
if (!err) {
template.userId = result.company.userId;
resolve();
}
})
});
});
}).then(function(){
console.log("templates");
console.log(templates);
self.setState({templates: templates});
});
},
後に再度レンダリングしない状態が正しいツールを反応させる反応します。 renderメソッドの がthis.state.templatesを呼び出しています。しかし、デフォルトではnullです。
getInitialState: function() {
return {templates: null}
},
setStateの実行後に再レンダリングが呼び出されないようです。ヌル
'setState'の前にconsole.logが起動しますか? –
あなたの 'templates'は' then'の中に 'log'するとき、それは何ですか? **ログ**内の –
は、 '[Object、Object、Object]'を表示します。 @BenjaminGruenbaum idk、どのようにチェックするのですか? –