- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在使用 Backbone 和 Marionette 创建一个简单的应用程序。它只是获取 WordPress 帖子列表(使用 API)并显示它。这是一个非常简单的应用程序,因此它没有模块化。
我有以下内容(全部放在同一个文件中):
if ( Backbone.history )
Backbone.history.start({ pushState: false });
if ( Backbone.history.fragment === '' )
API.listAllPosts();
else
API.listSinglePost( Backbone.history.fragment );
// Is not firing anything from here...
MyBlog.Router = Marionette.AppRouter.extend({
appRoutes: {
'': 'listPosts',
':post_name': 'listSingle'
},
listPosts: function() {
console.log('router');
API.listAllPosts();
},
listSingle: function(model) {
console.log('router, single');
API.listSinglePost(model);
}
});
// ...to here
var API = {
listAllPosts: function() {
// Fetch all posts and display it. It's working
},
listSinglePost: function(model) {
// Fetch a single post and display it. It's working
}
}
MyBlog.addInitializer(function() {
console.log('initializer'); // It's firing
new MyBlog.Router({
controller: API
});
});
如Derick Bailey, Marionette's creator, said关于在 naviagate 上使用触发器:
it encourages bad app design and it is strongly recommended you don’t pass
trigger:true
toBackbone.history.navigate
.
我在这里缺少什么?
最佳答案
在创建路由器实例之前启动 Backbone 历史记录。
只需将其移至创建路由器后即可。
MyBlog.addInitializer(function() {
new MyBlog.Router({ controller: API });
// should be started after a router has been created
Backbone.history.start({ pushState: false });
});
另一件事是回调 should be defined inside of a controller或者您应该将 appRoutes
更改为 routes
。
The major difference between
appRoutes
androutes
is that we provide callbacks on a controller instead of directly on the router itself. [...] As theAppRouter
extendsBackbone.Router
, you can also define aroutes
attribute whose callbacks must be present on theAppRouter
.
关于javascript - Backbone Marionette 没有射击路线,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44521589/
我需要实现射击机制。我需要射弹的连续运动,但我无法对其进行编码。此时,当我按下空格键时,程序就会卡住。我们将不胜感激。 from tkinter import * # creates window w
我遇到了一个问题。如果有任何帮助,我将不胜感激。 我正在尝试从玩家位置射击到鼠标点击位置。代码没有给我任何错误,根据我的逻辑,它应该可以工作,但它没有 它创建了项目符号对象,仅此而已。 //Bulle
我正在用 Java 开发一款 Android 游戏,其中我将有一个 Sprite 跟随用户的手指,并且应该每秒发射一颗子弹。换句话说,我试图附加一个每秒向上移动的位图。位图从主要角色 Sprite 的
我需要在 JQuery 中使用 focusin 和 focusout 触发器。我将它与 Bootstrap Popovers 一起使用。 目前,由于我认为某些奇怪的原因,它不起作用。 这有什么问题吗?
我是一名优秀的程序员,十分优秀!