我有一组需要共享相同集合的模块.
在模块启动之前,集合需要准备就绪.
我不确定如何以最干净的方式解决这个问题,我意识到这可能因项目而异,但这里有一些想法.
这是我想到的第一件事,只需在我调用"App.start()"之前加载集合.
然后我可以让它在全球范围内访问(不确定我喜欢这个.).
如果我构建应用程序使其具有主模块,则负责启动所有子模块.
然后我可以在启动任何子模块之前预加载所有重要数据,并确保它已准备就绪.
然后可以通过主模块API访问它.
我不知道这是不是很糟糕的设计,我对木偶的经验是有限的.
Atm我选择在"App.start()"之前加载集合,这让我觉得我也在预加载我的模板.
我引入了一个名为"CollectionManager"的"静态"对象,它充当我的集合的代理/访问点.并将在全球范围内提供.
// Templates that should be ready on start up
var arrTemplatesPaths = [...];
// Collections that i need to be ready and shared between modules.
var arrSharedCollections = [
{id:"groups", collection: GroupCollection}
];
// Preloading the vital data.
$.when.apply(null, [
Templates.fetch(arrTemplatesPaths),
CollectionManager.fetch(arrSharedCollections)
])
.then(function(){
App.start();
})
Run Code Online (Sandbox Code Playgroud)
然后需要访问集合的模块可以只调用CollectionManager.get(id)
var collection = CollectionManager.get("groups"); //@return Backbone.Collection
Run Code Online (Sandbox Code Playgroud)
这提供了一些结构,但我不确定我喜欢这么多.
所以在Marionette doc中挖了一点后,我注意到了Marionette.RequestResponse.
这提供了一种从模块内部请求数据的简洁方法,为我的方法创建了一个抽象级别,以一种烦人的方式耦合了一些东西.
所以我已将此行添加到应用程序中:
App.reqres.addHandler("getCollection", function …Run Code Online (Sandbox Code Playgroud) 我很难理解事件调度和儿童父母之间事件的约束是如何在令人敬畏的Marionette中工作的.
我可以从itemView触发自定义事件,这是正确的:
var Item = Marionette.ItemView.extend({
events: {
"click .foo": "do:something"
}
});
var itemCollection = Marionette.CollectionView.extend({
itemView: item,
initialize: function () {
this.on("itemview:do:something", this.onSomething, this);
}
}};
Run Code Online (Sandbox Code Playgroud)
是否有一些快捷方式可以绑定到itemView事件,比如DOM事件:
var itemCollection = Marionette.CollectionView.extend({
itemView: item,
itemviewevents: {
"itemview:do:something": "onSomething"
}
}};
Run Code Online (Sandbox Code Playgroud)
谢谢 :).
我使用grunt-contrib-compass pluckin,我只是不能让它按照我想要的方式运行,问题是我的css文件中的图像路径是错误的.
一直在玩这些参数,但我无法弄明白(悲伤面)
我的文件夹:
/root
/assets
/css
/images
/sprites <-- generated images
Run Code Online (Sandbox Code Playgroud)
以及我的gruntfile.js中的配置
compass: {
dist: {
options: {
sassDir: 'src/scss'
,cssDir: 'assets/css'
,raw: 'preferred_syntax = :sass\n'
,imagesDir: "assets/images/"
//,imagesPath: "assets/images/sprites/"
,generatedImagesDir: "assets/images/sprites/"
,generatedImagesPath: "assets/images/sprites/"
}
}
}
Run Code Online (Sandbox Code Playgroud)
我的css文件中的图片网址:
/assets/images/sprites/interface-s04f47928b4.png
Run Code Online (Sandbox Code Playgroud)
但它应该是:
../images/sprites/interface-s04f47928b4.png
Run Code Online (Sandbox Code Playgroud) 因此,我试图通过将ascciASCIIcode存储在字节数组中来将ASCII打印到屏幕上,但是它只是在屏幕上呈现了很多杂色。
; Message: hello
*=$033C
BYTE $48,$45,$49,$49,$4F
*=$1000
START
JSR PRINT_MESSAGE
EXIT
RTS
PRINT_MESSAGE
LDX #$00 ; initialize x to 0
LDA $033C,X ; grab byte
JSR $FFD2 ; render text in A with Subroutine:CLRCHN
INX ; Incriment X
CPX #$05 ; We stop at 5
BNE $1006 ; Else we loop
RTS
Run Code Online (Sandbox Code Playgroud)