0

我有一个小项目,右侧有一个板列表,左侧有一个活动板:

var updateBoard = function (b) {
  Boards.update(b._id, b)
  Session.set("active-board-id", b._id)
}

Template.controls.boards = function() {
  return Boards.find()
}

Template.controls.events({
  'click .board' : function (evt) {
    updateBoard(this)
  }
})

Template.board.b = function() {
  var b = Boards.findOne(Session.get('active-board-id'))
  return b || Boards.findOne()
}

Template.board.events({
  'click .cell': function (evt) {
    this.value += 1
  },
  'click .board': function (evt) {
    updateBoard(this)
  },
})

当您单击板上的单元格时,它应该增加。集合中的底层板会增加(您可以通过单击不同的板然后返回到第一个板来查看),但可见板不会增加。

我尝试将板直接存储在会话变量中并返回它。当我这样做时,可见板会增加,但其他选项卡中的板不会随之增加。我正在寻找一种解决方案,使所有选项卡中的所有查看者都可以立即看到对活动板的编辑。

4

1 回答 1

1

Figures I would solve it moments after posting the questions. Apparently findOne is not registering itself properly switching to find solves the problem.

Template.board.b = function() {
  var b = Boards.find(Session.get('active-board-id')).fetch()[0]
  //var b = Boards.findOne(Session.get('active-board-id'))
  return b || Boards.findOne()
}

UPDATE: This was a bug on the devel train for about one day. It turns out my timing is just good ;-)

于 2012-12-18T04:45:16.750 回答