我使用Ember.js与本地存储适配器.更新记录时我遇到了一个奇怪的问题.
我有一个与hasMany关系的帖子和评论模型:
App.Post = DS.Model.extend({
title: DS.attr('string'),
comments: DS.hasMany('comment', {
async: true
})
});
App.Comment = DS.Model.extend({
message: DS.attr('string')
});
Run Code Online (Sandbox Code Playgroud)
这些是我的帖子和评论控制器:
App.PostsController = Ember.ArrayController.extend({
newTitle: '',
actions: {
create: function() {
var title = this.get('newTitle');
var post = this.store.createRecord('post', {
title: title
});
this.set('newTitle', '');
post.save();
}
}
});
App.CommentsController = Ember.ArrayController.extend({
needs: "post",
post: Ember.computed.alias("controllers.post.model"),
newMessage: '',
actions: {
create: function() {
var message = this.get('newMessage');
var comment = this.store.createRecord('comment', {
message: message
});
var post = this.get('post');
var …
Run Code Online (Sandbox Code Playgroud) 我正在尝试运行node-gyp configure
,但遇到以下错误:
gyp: binding.gyp not found (cwd: /usr/local/bin)
gyp ERR! configure error
gyp ERR! stack Error: `gyp` failed with exit code: 1
gyp ERR! stack at ChildProcess.onCpExit (/usr/local/lib/node_modules/node-gyp/lib/configure.js:337:16)
gyp ERR! stack at ChildProcess.EventEmitter.emit (events.js:98:17)
gyp ERR! stack at Process.ChildProcess._handle.onexit (child_process.js:789:12)
gyp ERR! System Darwin 13.0.0
gyp ERR! command "node" "/usr/local/bin/node-gyp" "configure"
gyp ERR! cwd /usr/local/bin
gyp ERR! node -v v0.10.20
gyp ERR! node-gyp -v v0.12.2
gyp ERR! not ok
Run Code Online (Sandbox Code Playgroud)
我认为我在错误的目录中,但我不确定.我应该在哪个目录中运行它?
我想从CDN加载脚本,然后在React中执行该脚本公开的函数:
componentWillMount() {
console.log('componentWillMount is called');
const script = document.createElement('script');
script.src = 'https://foo.azurewebsites.net/foo.js';
document.body.appendChild(script);
}
componentDidMount() {
console.log('componentDidMount is called');
window.foo.render({
formId: '77fd8848-791a-4f13-9c82-d24f9290edd7',
}, '#container');
}
render() {
console.log('render is called');
return (
<div id="container"></div>
);
}
Run Code Online (Sandbox Code Playgroud)
脚本有时需要花时间加载(通常是第一次),什么时候componentDidMount()
被称为"foo"不可用,我得到这样的错误:
TypeError:无法读取未定义的属性'render'
如何componentDidMount()
在脚本成功加载后确保调用?
javascript ×2
ember-data ×1
ember.js ×1
has-many ×1
macos ×1
node-gyp ×1
node.js ×1
react-redux ×1
reactjs ×1