0

我有以下看法:

Whistlr.RegistrationView = Ember.View.extend
  templateName: "users/registration_form"

  submit: (event, view) ->
    event.preventDefault()
    event.stopPropagation()
    $.ajax
      url: '/users'
      type: "POST"
      data:
        "user[username]": @.get 'username'
        "user[email]": @.get 'email'
        "user[password]": @.get 'password'
        "user[password_confirmation]": @.get 'password_confirmation'
      success: (data) ->
        alert "Success!"
      error: (jqXHR, textStatus, errorThrown) ->
        alert jqXHR.responseText

使用此模板:

form
  label Username
  = input value=username type="text"
  label Email
  = input value=email type="text"
  label Password
  = input value=password type="password"
  label Password Confirmtation
  = input value=password_confirmation type="password"

  = input type='checkbox' checked=view.remember
  label Remember me

  = input type="submit" class="btn"

不幸的是,表单值没有绑定到视图,因此数据作为空白字段数组发送。看起来我无法@.get像使用标准模板中的表单一样简单地访问表单值。如何从视图中访问这些值?

4

1 回答 1

2

看起来问题出在我的模板中。我需要在每个属性的值字段中指定它绑定到视图。修改后的模板如下所示:

form
  label Username
  = input value=view.username type="text"
  label Email
  = input value=view.email type="text"
  label Password
  = input value=view.password type="password"
  label Password Confirmtation
  = input value=view.password_confirmation type="password"

  = input type='checkbox' checked=view.remember
  label Remember me

  = input type="submit" class="btn"
于 2013-07-19T19:34:36.443 回答