过滤serializeData中的数据

时间:2015-03-10 06:19:14

标签: backbone.js marionette mustache

我有一系列集合,我提供给我的CompositeView。 对于每个系列,我试图显示一个矩形,在里面显示该系列的前3个模型。

由于每个系列可能有超过3个模型,我想将其减少到总是3或更少。我正在使用小胡子,所以我不能在那里做,所以我想在childize或Show.Item的serializeData中做它但我很困惑我不理解serializeData函数的上下文。当我查看this时,它会给我一个窗口对象。

我应该在哪里进行过滤?

collection 1
  collection 1
    model 1
    model 2
    model 3
  collection 2
    model 1
    model 2
    model 3
    model 4   

enter image description here

  new Show.Items
    collection: collection

  class Show.Item extends App.Views.ItemView
    template: "templates/_item"

  class Show.Items extends App.Views.CompositeView
    template: "templates/show"
    childView: Show.Item
    childViewContainer: '.items'

1 个答案:

答案 0 :(得分:1)

似乎上下文失去了,解决这个问题的最简单方法是使用下划线bindall

来绑定所有方法