0
我想在子記錄中設置parent_id。如何在創建子燼時獲取父ID js
我的模型是食譜(id,title)和成分(id,about,recipe_id)。
我有一個窗體,我創建了許多配料的食譜。所有運作良好,但我不知道如何在創建父記錄後在子記錄中設置parent_id。
實施例:
我們創建配方(ID = 1,標題= 'Title01')。所以我們所有的成分將與1場recipe_id(ID = 2,約= '這是成分',recipe_id = 1)
recipe.js.coffee
App.Recipe = DS.Model.extend
title: DS.attr('string')
ingredients: DS.hasMany('App.Ingredient')
ingredient.js.coffee
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
你可以給我一個例子,如何做到這一點?在js或咖啡上它並不重要。 – EJIqpEP9 2013-04-25 18:07:26