所以我有一个集合我在应用程序开始处获取,像这样
module.exports = class Application extends Chaplin.Application
start: ->
# # You can fetch some data here and start app
# # (by calling `super`) after that.
Chaplin.mediator.styleCollection.fetch().then super
在home控制器接管并将用户带到相应的页面后,如下所示
module.exports = class HomeController extends Controller
beforeAction: ->
super
@reuse 'header', HeaderView, region: 'header'
@reuse 'nav', NavView, region: 'nav'
@reuse 'price', PriceView, region: 'price'
@reuse 'frame', FrameView, region: 'frame'
piece: ->
@view = new PieceView
region: 'main'
nextPage: "style"
@subscribeEvent "click:continue-btn", ()->
@redirectTo {url:"style"}
@publishEvent "update:progress", 25
, @
现在,当我通过我的HomeController到达PieceView时,我期望卓别林.mediator. stylecollection应该已经同步了,但是在重新加载期间几次显然集合还没有准备好。所以我放了一些控制台。下面是我看到的
console.log Chaplin.mediator.styleCollection输出(目前一切正常)
StyleCollection
_byId: Object
_events: Object
_previousSync: "syncing"
_syncState: "synced"
escape: function (value) {
length: 3
models: Array[3]
safe: function (value) {
__proto__: ctor
console.log卓别林.mediator. stylecollection . tojson()(这是事情发生的地方)
Array[0] <<<< the collection has nothing in it. I first thought the collection could still be syncing but that is not the case because the previous log showd _syncState: "synced"
任何想法吗?
好吧,这是一个愚蠢的修复。
在应用程序代码中,我做了以下操作
Chaplin.mediator.styleCollection.fetch()。Then => super