0
在编写我的第一个Ember-app的过程中,我一直无法弄清楚如何使用REST适配器将新资源发布到我的API。Ember Data(REST Adapter)创建模型实例但不POST POST
该应用程序成功检索资源列表并显示它,所以看起来我的模型已正确定义,并且适配器和API之间的通信起作用。当我点击CreateBugView按钮时,新的实例出现在列表中,所以这部分工作。但是,我可以在检查员看到没有对该API进行POST请求,并且当我刷新该页面时,该实例可预见地无法看到。
我正在使用Ember的1.0.0-rc.1版本以及今天克隆和构建的Ember Data版本。
以下是我的代码,我会感谢任何能够帮助我找出问题的人。
App = Em.Application.create()
# Templates
require 'templates/application'
require 'templates/index'
# Models
App.Bug = DS.Model.extend
name: DS.attr 'string'
# Views
App.CreateBugView = Em.View.extend
tagName: 'button'
click: (evt) ->
bug = App.Bug.createRecord
name: 'Sean'
# Routes
App.IndexRoute = Em.Route.extend
model: -> App.Bug.find()
setupController: (controller, bugs) ->
controller.set 'bugs', bugs
controller.set 'App', App
# Store
App.Store = DS.Store.extend
revision: 12
# Router
App.Router.map ->
@route 'index', path: '/'
App.initialize()
指数模板
<ul>
{{#each bugs}}
<li>{{name}}</li>
{{/each}}
</ul>
{{#view App.CreateBugView}}
Create new bug!
{{/view}}
感谢小费我送行需要提交,我发现这个答案,几乎完全匹配我的问题: http://stackoverflow.com/a/14490259/677985 虽然你的方式似乎从MVC分离的角度看起来更清洁,但我一定会看看ArrayController。 – 2013-03-12 20:30:32