Ember.js 取消编辑操作而不更新参数
目前我正在做一个编辑功能,它将弹出一个对话框,允许用户编辑他们的详细信息。编辑详细信息后,用户可以选择取消或保存编辑操作。但是现在,当用户单击cancel时,它也会更新,我想这是因为Ember.js 取消编辑操作而不更新参数,ember.js,Ember.js,目前我正在做一个编辑功能,它将弹出一个对话框,允许用户编辑他们的详细信息。编辑详细信息后,用户可以选择取消或保存编辑操作。但是现在,当用户单击cancel时,它也会更新,我想这是因为muthelper。我已经在route.js中硬编码了name的值,因此我使用model.name 这是我的template.hbs代码 Name: {{paper-input placeholder="Enter name" value=m
mut
helper。我已经在route.js
中硬编码了name
的值,因此我使用model.name
这是我的template.hbs代码
Name:
{{paper-input
placeholder="Enter name"
value=model.name
required = true
onChange=(action (mut model.name))
errorMessages=(hash required="Name is required.")}}
我尝试了两种我发现的方法:
1.我已尝试安装余烬数据更改跟踪器
,但它返回如下错误
Command failed: yarn add --dev ember-data-change-tracker --non-interactive
warning package-lock.json found. Your project contains lock files generated by tools other than Yarn. It is advised not to mix package managers in order to avoid resolution inconsistencies caused by unsynchronized lock files. To clear this warning, remove package-lock.json.
error ember-data-change-tracker@0.10.0: The engine "node" is incompatible with this module. Expected version ">= 10". Got "8.12.0"
error Found incompatible module.
yarn add v1.21.1
[1/5] Validating package.json...
[2/5] Resolving packages...
[3/5] Fetching packages...
info fsevents@2.1.2: The engine "node" is incompatible with this module. Expected version "^8.16.0 || ^10.6.0 || >=11.0.0". Got "8.12.0"
info "fsevents@2.1.2" is an optional dependency and failed compatibility check. Excluding it from installation.
info Visit https://yarnpkg.com/en/docs/cli/add for documentation about this command.
2.我曾尝试在controller.js中使用rollbackAttributes()
,但不起作用
closeEditDialog (ev) {
if(ev == 'cancel') {
this.set('showEditDialog',false);
let name = this.get('model.name')
if (name.hasDirtyAttributes) {
name.rollbackAttributes();
}
}
我找到了另一个解决方案,但我不知道如何实现它
您的问题是在属性上调用
rollbackAttributes()
,但必须在模型上调用它:
let model = this.get('model');
if (model.hasDirtyAttributes) {
model.rollbackAttributes();
}
这里有两个注释:
model.hasDirtyAttributes===false,则code>rollbackAttributes()
将不会执行任何操作什么不适用于
rollbackAttributes()
?这确实是正确的解决办法。您是否已检查是否实际运行了rollbackAttributes()
?除此之外,我真的可以推荐与许多友好的人一起加入,并以一种更具互动性的方式来帮助您和理解您的问题。它返回错误-name。回滚属性
不是一个函数。顺便说一句,谢谢你的推荐,我稍后会加入。这确实帮助我看到了你的打字错误。我没有为此生成模型,this.model从route.js返回模型。这是导致回滚属性不工作的原因吗?从model
您的route.js
返回什么hasDirtyAttributes
确实是一个ember数据
功能。您必须在模型的实例上调用它。