我有以下看法:
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
像使用标准模板中的表单一样简单地访问表单值。如何从视图中访问这些值?