2013-04-25 1 views
0

자식 레코드에 parent_id를 설정하려고합니다.자식을 만들 때 부모 ID를 가져 오는 방법 js

내 모델은 Recipe (id, title) 및 Ingredients (id, about, recipe_id)입니다.

나는 많은 재료로 조리법을 만드는 형식을 가지고 있습니다. 모두 잘 작동하지만 부모 레코드를 만든 후에 하위 레코드에서 parent_id를 설정하는 방법을 모르겠습니다.

예 :

우리 레시피 작성 (ID = 1, 표제 = 'Title01'). 그래서 우리의 모든 성분 (약 = '이 성분이'에는 Recipe_ID = 1 ID = 2)

recipe.js.coffee

App.Recipe = DS.Model.extend 
    title: DS.attr('string') 
    ingredients: DS.hasMany('App.Ingredient') 

ingredient.js.coffee

1 필드에는 Recipe_ID이있을 것이다
App.Ingredient = DS.Model.extend 
    about: DS.attr('string') 
    recipe: DS.belongsTo('App.Recipe') 

new.emblem 나는 커피 스크립트를 모르는

h1 Create recipe 

form 
    div 
    label{bindAttr for='title.elementId'} Title 
    Ember.TextField valueBinding='title' name='title' viewName='title' 

    div 
    label{bindAttr for='about.elementId'} About 
    Ember.TextArea valueBinding='about' name='about' viewName='about' 

    #ingredients 
    h3 Ingredients 
    each ingredient in content.ingredients itemViewClass='App.ItemView' 
     h3= this.view.rebasedIndex 
     .control-group 
     .controls 
      Ember.TextField valueBinding='ingredient.about' 
      a{ action removeIngredient ingredient target='controller' } href='#' Remove 
    div 
     a{ action addIngredient target='controller' } href='#' Add Ingredient 

    button.btn.btn-success{ action save this } Create 
    button.btn.btn-inverse{ action cancel this } Cancel 

답변

0

(여기 내가 부모 레시피 및 어린이를 만들 재료를)하지만, 각 성분보기에 대해 parentIdBinding을 만들 수 있습니까?

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

가 어떻게이 작업을 수행하는 나에게 예를 제공 할 수 있습니다 : 예를 제공

EDIT? js 또는 커피에 상관 없습니다. – EJIqpEP9

관련 문제