主干路由(spine js mvc)如何工作?

发布于 2024-12-17 02:31:52 字数 588 浏览 2 评论 0原文

我已经尝试了 Spinejs 库几天,我在 Spinejs.com 上有文档,但直到现在,我仍然不知道 Spine 路由到底是如何工作的。从文档中,我知道如何创建新路由并将其添加到 Spine 路由中。但它是如何运作的呢? 我尝试创建一个带有 2 个控制器任务和 TaskList 的示例,这些控制器从 Spine.Controller 扩展,我还添加了 2 个路由控制器:“#/task”和“#/tasklist”:

Spine.route.add("#/task");
Spine.route.add("#/tasklist");
Spine.route.setup();

在任务和 TaskList 控制器中,我只是在他们的构造函数。

但是当我浏览:“http://hellospine.html/#task”->什么也没发生 然后“http://hellospine.html/#tasklist”->什么也没发生 我认为,url“#task”和“#tasklist”中的路由值让spine调用适当控制器的构造函数,但它不起作用。

你有什么想法吗?我应该再配置以使其运行适当的控制器吗?我也想知道spine路由的工作流程,请帮助我,非常感谢!

I have tried Spinejs library for a few days, I have the document on Spinejs.com but till now, I still don't know how exactly Spine routing work. From the document, I know how to create a new route and add them to Spine routing. But how it work?
I tried to create an example with 2 controller Task and TaskList extends from Spine.Controller, I also did add 2 routing controllers: "#/task" and "#/tasklist":

Spine.route.add("#/task");
Spine.route.add("#/tasklist");
Spine.route.setup();

in Task and TaskList controller, I simply alert an message in their constructor.

But when I browse: "http://hellospine.html/#task" -> nothing happen
then "http://hellospine.html/#tasklist" -> nothing happen
I thought that, the route values in url "#task" and "#tasklist" let spine call constructor of appropriate controller, but it's not working.

Do you have any idea ? Should I config anymore to make it run appropriate controller ? I also wanna know work flow of spine routing, please help me, thanks a lot!

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

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

发布评论

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

评论(1

半葬歌 2024-12-24 02:31:52

3 件事:

  1. Spine.Route.add 应该在控制器之外使用。
  2. 路线不需要#
  3. 您必须指定到达路线时要执行的回调函数

,如下所示:

Spine.Route.add('/hi', function () {
    alert('Hey you!');
});
Spine.Route.setup()

demo 此处

但请参阅http://spinejs.com/docs/routing

干杯。

3 things:

  1. Spine.Route.add is meant to be used out of controllers.
  2. route does not need #.
  3. You have to specify a callback function to execute when the route is reached

so:

Spine.Route.add('/hi', function () {
    alert('Hey you!');
});
Spine.Route.setup()

demo here

But please refer to http://spinejs.com/docs/routing

Cheers.

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