未调用backbone.sync请求
我已经在不同的 js 文件中创建了模型、视图和集合,并且我正在使用 require.js 加载所有文件,执行数据插入,但是当我编辑或删除数据时,它不会执行,而在编辑数据而不是发送 PUT 请求时,它将发送POST 请求并插入新数据。可能是模型实例未与视图连接。
我使用nodejs进行服务器端渲染,使用backbonejs进行客户端渲染。我的模板具有 .html 扩展名,并且使用 ejs 视图引擎。
i have created model, view and collections in different js file and i am loading all files using require.js data insertion is performed but when i am editing or deleting data it will not performed and while editing data instead of sending PUT request it will send POST request and new data is inserted. may be the model instance is not get connected with view.
I am using nodejs for server side rendering and backbonejs for client side rendering. my templates having a .html extension n using ejs view engine.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当您发布新数据来创建对象时,您的其余路由是否会响应 ID?您的模型将查找成功创建调用的 JSON 响应。您真正需要的只是 ID,但任何 ID 都可以包含您希望在模型上设置的任何其他信息。
您真正需要响应的是 201 Created 和
{ "id": "NzIdHda" }
如果 Backbone 模型没有 ID,它们将始终 POST 并尝试创建新的。一旦他们获得了 ID(无论是在实例化时还是作为 .save() 的结果),他们将不再认为自己是“新的”。
When you POST new data to create an object, does your rest route respond with an ID? Your model will be looking for a JSON response from the successful create call. All you really need is ID, but any can include any other info you would like to be set on the model.
All you would really need to respond with is a 201 Created and
{ "id": "NzIdHda" }
If Backbone models do not have an ID, they will always POST and try and create new. Once they get an ID (either on instantiation or as the result of a .save(), they will no longer consider themselves "new".