ChaplinJS集合同步问题

时间:2014-07-11 19:10:28

标签: chaplinjs

所以我有一个我在应用程序中启动的集合,如此

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"

有什么想法吗?

1 个答案:

答案 0 :(得分:0)

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

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

  

Chaplin.mediator.styleCollection.fetch()。then =&gt;超

相关问题