Jquery 余烬模式在关闭时路由到错误的url
我有一个ember应用程序,它有一个Jquery 余烬模式在关闭时路由到错误的url,jquery,twitter-bootstrap,ember.js,Jquery,Twitter Bootstrap,Ember.js,我有一个ember应用程序,它有一个用户模型,具有CRUD功能。Create和Edit模板都在twitter引导模式中呈现。我的问题是,当我在模式中单击取消或保存更改时,我希望应用程序返回到用户模板。相反,当我单击其中一个按钮时,模式消失,但url分别保持在/users/create或/users/edit。我试着按如下方式更改路由,但没有效果。我的modals是大量谷歌搜索和整合不同示例代码的结果,因此我不确定userEditView中的close操作是否真的起作用。有人能帮忙吗 App.Us
用户
模型,具有CRUD功能。Create
和Edit
模板都在twitter引导模式中呈现。我的问题是,当我在模式中单击取消
或保存更改
时,我希望应用程序返回到用户
模板。相反,当我单击其中一个按钮时,模式消失,但url分别保持在/users/create或/users/edit。我试着按如下方式更改路由,但没有效果。我的modals是大量谷歌搜索和整合不同示例代码的结果,因此我不确定userEditView
中的close
操作是否真的起作用。有人能帮忙吗
App.UserEditView = Ember.View.extend({
templateName: "user/edit",
title: "",
content: "",
classNames: ["modal", "fade"],
didInsertElement: function() {
this.$().modal("show");
this.$().one("hidden", this._viewDidHide);
},
// modal dismissed by example clicked in X, make sure the modal view is destroyed
_viewDidHide: function() {
if (!this.isDestroyed) {
this.destroy();
}
},
// here we click in close button so _viewDidHide is called
close: function() {
this.$(".close").click();
//This is where I've tried to change the routing
this.transitionToRoute('users');
}
});
我的模板:
<script type = "text/x-handlebars" id = "user/edit">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h4 class="modal-title">Edit User</h4>
</div>
<div class="modal-body">
<div class = "input-group">
<h5>First Name</h5>
{{input value=firstName}}
<h5>Last Name</h5>
{{input value=lastName}}
<h5>Email</h5>
{{input value=email}}
</div>
</div>
<div class="modal-footer">
<a {{action close target="view"}} href="#" class="btn btn-default">Cancel</a>
<a {{action "save"}} class="btn btn-primary">Save changes</a>
</div>
</div><!-- /.modal-content -->
</div><!-- /.modal-dialog -->
</script>
我的路线是:
App.UsersCreateRoute = Ember.Route.extend({
model: function(){
// the model for this route is a new empty Ember.Object
return Em.Object.create({});
},
renderTemplate: function(){
this.render('user.create', {
controller: 'usersCreate'
});
}
});
通过调用
transitiono(“U路线”)
可以从余烬routes
调用到路线的转换,通过调用transitionotroute(“U路线”)
可以调用到控制器。如果需要从一个余烬视图
转换,则在视图中调用this.controller.transitionRoute(“用户”)代码>
在下面的示例中,在create user
中进行了一些调整,以试验引导模式淡入/淡出,但通常遵循您的代码样式来演示我认为您描述的内容
谢谢你的精彩演讲!当我点击cancel时,这个功能非常有效,但是当我保存一条新记录时,模式会关闭,但是页面仍然淡出,url仍然位于/users/newuserid。有什么建议吗?@盗书贼很高兴能帮上忙!当我选择save
时,会显示两个警报对话框,并向用户过渡(在chrome 31.x、ff 25.0中测试)。嗯,我在某个地方犯了一个错误,因为视图中的警报没有被触发!
App.UsersCreateRoute = Ember.Route.extend({
model: function(){
// the model for this route is a new empty Ember.Object
return Em.Object.create({});
},
renderTemplate: function(){
this.render('user.create', {
controller: 'usersCreate'
});
}
});