- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我想做的是将 ember-cli-mirage 集成到这个待办事项应用程序中,https://github.com/ember-cli/ember-cli-todos .此应用程序使用 Ember 2.0 或更高版本。设置:
我已验证该应用程序是否按照宣传的方式运行(除了与此处无关的一件小事)。我可以创建、更新和删除待办事项。 todo 应用程序使用 ember-data-fixture-adapter/FIXTURES 为应用程序播种数据。
我集成ember-cli-mirage的步骤是:
如果有人需要查看,我会发布 app/mirage/{config.js,factories/post.js,scenarios/default.js} 的代码,但它基本上只是 ember- cli-mirage 页面(“user”模型名称替换为“post”)。
我重新启动了 ember 服务器。除了删除待办事项外,一切正常。记录删除是通过按下“x”按钮完成的,当您将指针移动到待办事项的右侧时,该按钮将出现。我发现它在记录删除的 save() 部分失败了。删除记录的代码(使用“x”按钮界面)位于 app/components/todo-item/component.js 中,它看起来像这样:
removeTodo() {
var todo = this.get('todo');
todo.deleteRecord();
todo.save();
}
当我尝试删除待办事项时,浏览器控制台打印“请求成功:DELETE/todos/n”(“n”是待办事项 ID),然后它会打印一条神秘的错误消息以及堆栈跟踪。
我注释掉了“todo.save();”上面的线。当我删除一个待办事项时,删除仍然失败,但在控制台上,“成功请求:DELETE/todos/n”消息后不再有错误消息。
所以我更改了上面的 removeTodo 代码,试图使错误消息更清楚。我把它改成了这样:
todo.save().then(function() {
console.log('Save OK.');
}).catch((err) => {
console.log('Save failed.');
console.log(err.message);
});
我在这里和那里尝试了各种更改,但始终出现的错误消息是:
Assertion Failed: An adapter cannot assign a new id to a record that already has an id. had id: 3 and you tried to update it with undefined. This likely happened because your server returned data in response to a find or update that had a different id than the one you sent.
我看到一条错误消息,上面有类似“normalizeserializer...”的文本,但我忘记复制整个消息。
我添加了一个适配器:
shell> ember g adapter application
// app/adapters/application.js
import DS from 'ember-data';
export default DS.JSONAPIAdapter.extend({
});
但这并没有解决问题。
顺便说一句,todo 项目的创建,也调用了 todo 项目的保存,是有效的。代码位于 app/components/todos-route/component.js 中:
createTodo() {
const store = this.get('store');
// Get the todo title set by the "New Todo" text field
var title = this.get('newTitle');
if (title && !title.trim()) {
this.set('newTitle', '');
return;
}
// Create the new Todo model
var todo = store.createRecord('todo', {
title: title
});
// Clear the "New Todo" text field
this.set('newTitle', '');
// Save the new model
todo.save();
}
最佳答案
DELETE
到 /todos/:id
的 Mirage 模拟是什么样的?看起来您正在使用包含 id
的 JSON 负载响应 DELETE 请求,这会导致问题。
相反,您可以尝试返回空响应主体的内容,例如
this.del('/todos/:id', (db, request) => {
let id = request.params.id;
db.todos.remove(id);
return new Mirage.Response(204, {}, {});
});
(此代码未经测试,但希望您能理解)。
另一个小问题,模型上有一个 destroyRecord
方法,它基本上同时执行 deleteRecord
和 save
。
关于javascript - Ember destroyRecord(或 deleteRecord 然后保存)使用 ember-cli-mirage 失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33094737/
每当他尝试删除项目时,我都要求在有效负载中包含用户的评论。到目前为止,我有这个: let remarks = this.get('remarks'); let id = this.get('itemI
当我打电话时deleteRecord()在我的一些关系中,Ember Data 发送了(成功)DELETE请求,但该记录不会从 View 中删除。我正在使用 render 显示它像这样的 helper
我正在使用一个简单的 Ember.ArrayController在具有 ember-data 的应用程序中(最新), ember rc6和一个库存 REST Controller 。 我在数组 Con
问题在于,我的提要定义包含具有多对多关系的部分。这意味着,1 个提要定义可以有多个部分,1 个部分可以有多个提要定义。 当我显示费用时,我必须显示与其关联的部分的列表。请检查模型中的部分。 如果有人想
在 Controller 中: actions: { selectDelete: function(note) { console.log('selec
我有一个 Em.ArrayController里面有一堆记录。它们都由 itemController 控制。 . App.ColorsController = Em.ArrayController.e
我尝试使用 Java 管理客户端 API 的删除记录方法从我的 kafka 主题中删除消息。以下是我尝试过的步骤 1. I pushed 20000 records to my TEST-DE
我想做的是将 ember-cli-mirage 集成到这个待办事项应用程序中,https://github.com/ember-cli/ember-cli-todos .此应用程序使用 Ember 2
我正在观察 localStorage.clear() 之后的数据复活或 deleteRecord() ( jsbin example ) 在我的 ember 应用程序中被调用。 请按照以下步骤复制问题
我正在尝试在我的应用程序中使用 ember-data 来管理关注者/关注者关系。我遇到了一个问题,如果用户点击开关打开/关闭 ember 会抛出“在 root.deleted.saved 状态下尝试处
我正在使用 jQuery UI Sortable 和 Ember.js 对项目列表进行排序,它似乎工作得很好,直到我去删除一个 Ember 数据记录。模型已正确删除,但 UI 不会更新以反射(refl
我是一名优秀的程序员,十分优秀!