0

所以我有一个集合,我在应用程序开始时这样获取

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

在这个家庭控制器接管并将用户带到适当的页面之后,像这样

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 时,我希望 Chaplin.mediator.styleCollection 应该已经同步,但是在重新加载期间有几次显然集合还没有准备好。所以我输入了一些console.logs,这就是我看到的

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 Chaplin.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"

有什么想法吗?

4

1 回答 1

0

好的,这是一个愚蠢的修复。

在应用程序代码中我做了以下

Chaplin.mediator.styleCollection.fetch().then => super

于 2014-07-11T19:26:15.653 回答