我无法embedded hasMany使用ember数据正常工作.
我有类似的东西
App.Post = DS.Model.extend({
comments: DS.hasMany('App.Comment')
});
App.Comment = DS.Model.extend({
post: DS.hasMany('App.Post'),
name: attr('string')
});
Run Code Online (Sandbox Code Playgroud)
我的API返回以下内容GET /post:
[
{
id: 1
comments: [{name: 'test'}, {name: 'test2'}]
},
...
]
Run Code Online (Sandbox Code Playgroud)
我需要发送以下内容POST /post:
[
{
comments: [{name: 'test'}, {name: 'test2'}]
},
...
]
Run Code Online (Sandbox Code Playgroud)
我想与Ember模型合作并让他们提出适当的要求:
var post = App.store.createRecord(App.Post, hash_post_without_comments);
post.get('comments').createRecord(hash_comment);
App.store.commit(); // This should call the POST api
Run Code Online (Sandbox Code Playgroud)
和
var posts = App.store.find(App.Post); // This should call the GET api
Run Code Online (Sandbox Code Playgroud)
当我尝试类似的东西时post: DS.hasMany('App.Post', {embedded: …
当我运行ember new命令来创建一个新项目时,项目将在我的主目录中创建,而不是new从执行命令的目录中创建.
谁知道为什么?
我有一个带有多个键的哈希值和一个字符串,其中包含哈希中的无键或其中一个键.
h = {"k1"=>"v1", "k2"=>"v2", "k3"=>"v3"}
s = "this is an example string that might occur with a key somewhere in the string k1(with special characters like (^&*$#@!^&&*))"
Run Code Online (Sandbox Code Playgroud)
检查是否s包含任何密钥的最佳方法是什么,如果包含h,则返回它包含的密钥的值?
例如,对于上面的h和的例子s,输出应该是v1.
编辑:只有字符串是用户定义的.哈希将始终相同.