首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >ChaplinJS集合同步问题

ChaplinJS集合同步问题
EN

Stack Overflow用户
提问于 2014-07-12 03:10:28
回答 1查看 37关注 0票数 0

所以我有一个在应用程序中获取的集合,如下所示

代码语言:javascript
复制
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

在这个主控制器接管并将用户带到适当的页面之后,如下所示

代码语言:javascript
复制
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输出(到目前为止一切正常)

代码语言:javascript
复制
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() (这就是问题所在)

代码语言:javascript
复制
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"

有什么想法吗?

EN

回答 1

Stack Overflow用户

发布于 2014-07-12 03:26:16

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

在应用程序代码中,我执行了以下操作

Chaplin.mediator.styleCollection.fetch().then =>超级

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/24704852

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档