JavascriptMVC:如何调用控制器的历史方法?

发布于 2024-11-14 20:03:09 字数 568 浏览 7 评论 0原文

JMVC 有一个历史记录插件,可让您与 URL 的哈希片段进行交互。例如,您可以更改 URL 的 #hash 部分,以使应用程序内的某些操作可添加书签,并允许人们使用浏览器的后退按钮进行导航。

不幸的是,我使用它的运气并不好。

以下代码创建一个 JMVC 控制器,尝试将浏览器 URL 设置为 example.com/myApp#controller/someController 之类的内容。但是,什么也没有发生,因为历史记录插件定义的 redirectTo() 方法未定义。我也尝试过History.redirectTo()

steal.plugins("jquery/controller/history");
$.Controller.extend('MyControllerWithHistory', {}
{
'.item click': function( el ){
   redirectTo({controller:'someController'});
}
});

我做错了什么?

谢谢!

JMVC has a History plugin that lets you interact the URL's hash fragment. For example, you can change the #hash part of the URL to make certain actions inside your app bookmarkable, and allow people to navigate using the browser's back button.

Unfortunately, I'm not having much luck using it.

The following code creates a JMVC controller that tries to set the browser URL to something like example.com/myApp#controller/someController. However, nothing happens because the redirectTo() method that the History plugin says it defines, is undefined. I've also tried History.redirectTo().

steal.plugins("jquery/controller/history");
$.Controller.extend('MyControllerWithHistory', {}
{
'.item click': function( el ){
   redirectTo({controller:'someController'});
}
});

What am I doing wrong?

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

陪你到最终 2024-11-21 20:03:09

您是否尝试过 this.redirectTo()

steal.plugins("jquery/controller/history");
$.Controller.extend('MyControllerWithHistory', {},
{
'.item click': function( el ){
    this.redirectTo({controller:'someController'});
}
});

通过包含历史记录插件,您可以向 $.Controller 添加诸如 redirectTo 之类的方法。

Have you tried this.redirectTo():

steal.plugins("jquery/controller/history");
$.Controller.extend('MyControllerWithHistory', {},
{
'.item click': function( el ){
    this.redirectTo({controller:'someController'});
}
});

By including the history plugin you are adding methods such as redirectTo to $.Controller.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文