2013-02-01 15 views
0

所以每次我創建一個新的子公司將其保存到數據庫中,但沒有名字。我不能爲我的生活弄清楚這一點。當創建在Backbone.js的新對象我的屬性保存爲無

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" /> 
+0

的價值是得到從請求的瀏覽器發佈? – anushr

回答

0

嘗試使用類而不是ID來表示您的輸入字段。您可能在頁面的其他地方有另一個#first,這可能會導致只找到第一個(因瀏覽器而異)。

您也可以在視圖中範圍使用this.$el.find(<selector>)

+0

頁面上沒有其他#first id。這是一些小事,我只是似乎無法把一個手指上 –

+0

當我做console.long($(「#第一」)。VAL())獲得正確的字符串。它只是不保存數據庫。它只是保存爲零。 –

相關問題