0

每次,我在 Backbone.Marionette.CollectionView 中重置 Backbone.Collection,IE8 都会抛出错误:

Function.prototype.apply:参数为空或未定义

同样的情况也适用于 emptyView。

我的 CoffeeScript 代码(以下 js 版本):

Collection = Backbone.Collection.extend
url       : '/videos.json'
baseModels: []
initialize : -> 
  GIS.VL.vent.on 'specialization:selected', @onSpecializationSelected, @
  @on 'reset', @onFirstSync, @

onFirstSync : (a)->
  @off 'reset', @onFirstSync, @
  @baseModels = @models
  console.log @models

onSpecializationSelected : (model)-> 
  if model.id < 0
    @reset @baseModels
  else
    filteredItems = _.filter @baseModels, (item)->
      specializations = _.map item.get('specializations'), (specialization) ->
        specialization.id 
      -1 < _.lastIndexOf specializations, model.id
    @reset filteredItems

Javascript版本:

var Collection;

Collection = Backbone.Collection.extend({
  url: '/videos.json',
  baseModels: [],
  initialize: function() {
    GIS.VL.vent.on('specialization:selected', this.onSpecializationSelected, this);
    return this.on('reset', this.onFirstSync, this);
  },
  onFirstSync: function(a) {
    this.off('reset', this.onFirstSync, this);
    this.baseModels = this.models;
    return console.log(this.models);
  },
  onSpecializationSelected: function(model) {
    var filteredItems;
    if (model.id < 0) {
      return this.reset(this.baseModels);
    } else {
      filteredItems = _.filter(this.baseModels, function(item) {
        var specializations;
        specializations = _.map(item.get('specializations'), function(specialization) {
          return specialization.id;
        });
        return -1 < _.lastIndexOf(specializations, model.id);
      });
      return this.reset(filteredItems);
    }
  }
});

我正在使用带有 Handlebars 模板的最简单的 CollectionView:

  VideosView = Backbone.Marionette.CollectionView.extend
    tagName   : 'div'
    itemView  : VideoView
    collection: new Collection
    config: 
      itemsPerPage: 3

    initialize: (options)->
      console.log 'initialize'

      # override defaults:
      @config           = _.extend @config, options

Javascript 版本如下:

var VideosView;

VideosView = Backbone.Marionette.CollectionView.extend({
  tagName: 'div',
  itemView: VideoView,
  collection: new Collection,
  config: {
    itemsPerPage: 3
  },
  initialize: function(options) {
    console.log('initialize');
    return this.config = _.extend(this.config, options);
  }
});
4

2 回答 2

3

这原来是 Marionette 中的一个错误,.apply使用 null 或未定义的arguments参数调用。

Marionette 及其依赖项已更新以解决此问题,并且该修复不在开发分支中(请参阅此票证:https ://github.com/marionettejs/backbone.marionette/issues/368 )。

如果您需要立即进行此修复,则需要从dev分支中获取木偶构建:https ://github.com/marionettejs/backbone.marionette/tree/dev/lib

如果您使用的是“核心”构建,请务必同时更新 Wreqr 和 EventBinder。BabySitter 不需要任何更新。

于 2012-12-06T18:48:34.560 回答
2

确保所有对象都没有杂散逗号:

ie8err: { something: 1, something: 2, } //Error in IE8 and below.

我不肯定就是这样,但它闻起来可能是这样。

于 2012-12-06T16:15:05.513 回答