Javascript 在backbone.js中创建新对象时,我的属性另存为nil
因此,每次我创建一个新的分支,它保存到数据库中,但没有名字。我一辈子都搞不清楚这件事Javascript 在backbone.js中创建新对象时,我的属性另存为nil,javascript,ruby-on-rails,ruby,ruby-on-rails-3,backbone.js,Javascript,Ruby On Rails,Ruby,Ruby On Rails 3,Backbone.js,因此,每次我创建一个新的分支,它保存到数据库中,但没有名字。我一辈子都搞不清楚这件事 class Shop.Views.AffiliatesNew extends Backbone.View template: JST['affiliates/new'] events: 'submit .form-container': 'addAffiliate' initialize: -> @collection.on('reset', @render, t
class Shop.Views.AffiliatesNew extends Backbone.View
template: JST['affiliates/new']
events:
'submit .form-container': 'addAffiliate'
initialize: ->
@collection.on('reset', @render, this)
@collection.on('add', @render, this)
render: ->
$(@el).html(@template(affiliates: @collection))
this
addAffiliate: (event) ->
event.preventDefault()
@collection.create({
name: $('#first').val()
})
<input type="text" name="name" id="first"/> <br />
.form-title
.submit-container
<input id="affiliate-button" type="submit" value="Submit" />
class Shop.Views.affiliateNew.View
模板:JST['affiliates/new']
活动:
“submit.form容器”:“addAffiliate”
初始化:->
@collection.on('reset',@render,this)
@collection.on('add',@render,this)
渲染:->
$(@el.html(@template(附属公司:@collection))
这
addAffiliate:(事件)->
event.preventDefault()
@集合。创建({
名称:$('#first').val()
})
.表格名称
.提交容器
尝试使用类而不是ID来表示输入字段。您可能在页面的其他位置有另一个#first
,这可能导致仅找到第一个(因浏览器而异)
您还可以通过使用
this.$el.find()
页面上的无其他第一个id在视图中确定范围。这是一个很琐碎的东西,当我使用console时,我似乎一根手指都插不上。long($('#first').val())我得到了正确的字符串。它只是不能与数据库一起保存。它只保存为nil。该值是否从请求中的浏览器发布?