【问题标题】:filtering data in serializeData在serializeData中过滤数据
【发布时间】:2015-03-10 14:29:15
【问题描述】:

我有一组我提供给我的 CompositeView 的集合。 对于每个集合,我试图显示一个矩形,并在其中显示该集合的前 3 个模型。

由于每个集合可能有 3 个以上的模型,我想将其缩减为始终为 3 个或更少。我正在使用 mustache,所以我不能在那里做,所以我想在 serializeData 中为 childView 或 Show.Item 做,但我很困惑,我不了解 serializeData 函数的上下文。当我查看this 时,它给了我窗口对象。

我应该在哪里进行过滤?

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

  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'

【问题讨论】:

    标签: backbone.js marionette mustache


    【解决方案1】:

    似乎this的上下文丢失了,解决这个问题的最简单方法是使用下划线的bindall绑定所有方法

    【讨论】:

    • 谢谢,我该怎么做呢?我正在使用咖啡脚本
    猜你喜欢
    • 2018-08-02
    • 2017-07-27
    • 2021-06-07
    • 2014-08-05
    • 2010-10-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-01-29
    相关资源
    最近更新 更多