Backbone.js Backbone.marionette compositeview忽略addItemView的索引

Backbone.js Backbone.marionette compositeview忽略addItemView的索引,backbone.js,marionette,Backbone.js,Marionette,我正在使用Backbone.Marionette的CompositeView,我想在集合的索引0处插入一个新模型,并将其显示为合成中的第一个视图 我有以下代码来插入元素: PlansApp.Plans.collection.unshift new PlansApp.Plan data 问题是CompositeView忽略了集合中新插入项的索引 在Backbone.marionete中,appendHtml方法如下所示: appendHtml: function(collectionView

我正在使用Backbone.Marionette的CompositeView,我想在集合的索引0处插入一个新模型,并将其显示为合成中的第一个视图

我有以下代码来插入元素:

PlansApp.Plans.collection.unshift new PlansApp.Plan data
问题是CompositeView忽略了集合中新插入项的索引

在Backbone.marionete中,appendHtml方法如下所示:

  appendHtml: function(collectionView, itemView, index){
    collectionView.$el.append(itemView.el);
  },
从不使用索引参数

新插入的视图将始终放置在组合的末尾


如何使其显示在位置0处?

这是出于设计考虑,因为在直接支持已排序集合的过程中,已确定了大量边缘案例

添加了
索引
参数,以便开发人员可以在其应用程序中单独添加支持。有一个wiki页面显示了如何执行此操作的示例:


Derick最初的答案对于当前版本的木偶来说有点过时,而wiki只包含collectionview的一个示例

以下是我目前用于CompositeView的内容:

appendHtml: (collectionView, itemView, index) ->
  $container = @getItemViewContainer(collectionView)
  if index is 0
    $container.prepend itemView.el
  else
    childAtIndex = $container.children().eq(index)
    if childAtIndex.length
      childAtIndex.before itemView.el
    else
      $container.append itemView.el

wiki页面实际上位于此处:
appendHtml: (collectionView, itemView, index) ->
  $container = @getItemViewContainer(collectionView)
  if index is 0
    $container.prepend itemView.el
  else
    childAtIndex = $container.children().eq(index)
    if childAtIndex.length
      childAtIndex.before itemView.el
    else
      $container.append itemView.el