Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ember.js/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 如何在创建子ember js时获取父id_Ruby On Rails_Ember.js_Ember Data - Fatal编程技术网

Ruby on rails 如何在创建子ember js时获取父id

Ruby on rails 如何在创建子ember js时获取父id,ruby-on-rails,ember.js,ember-data,Ruby On Rails,Ember.js,Ember Data,我想在子记录中设置父\u id 我的模型是菜谱(id,标题)和配料(id,关于,菜谱) 我有一个表格,我用许多配料制作食谱。这一切都很好,但我不知道如何在创建父记录后在子记录中设置父\u id 示例: 我们创建了配方(id=1,title='Title01')。因此,我们所有的配料都将具有字段recipe\u id和1(id=2,about='this is component',recipe\u id=1) 配方咖啡 App.Recipe = DS.Model.extend title:

我想在子记录中设置父\u id

我的模型是菜谱(id,标题)和配料(id,关于,菜谱)

我有一个表格,我用许多配料制作食谱。这一切都很好,但我不知道如何在创建父记录后在子记录中设置父\u id

示例:

我们创建了配方(id=1,title='Title01')。因此,我们所有的配料都将具有字段recipe\u id和1(id=2,about='this is component',recipe\u id=1)

配方咖啡

App.Recipe = DS.Model.extend
  title: DS.attr('string')
  ingredients: DS.hasMany('App.Ingredient')
App.Ingredient = DS.Model.extend
  about: DS.attr('string')
  recipe: DS.belongsTo('App.Recipe')
成分:咖啡

App.Recipe = DS.Model.extend
  title: DS.attr('string')
  ingredients: DS.hasMany('App.Ingredient')
App.Ingredient = DS.Model.extend
  about: DS.attr('string')
  recipe: DS.belongsTo('App.Recipe')
new.徽章(我在这里创建父配方和子配方)


我不知道咖啡脚本,但你能为每个成分视图创建一个parentIdBinding吗

编辑并提供一个示例:

{{#each recipe in recipes}}
    {{#each ingredient in ingredients}}
        {{view ingredientView parentBinding="recipe"}}
    {{/each}}
{{/each}}

你能给我举个例子吗?在js或咖啡上,这并不重要。