【问题标题】:Backbone collection bug in IE9IE9 中的主干收集错误
【发布时间】:2013-11-09 08:30:40
【问题描述】:

无法理解问题所在。

当在骨干集合上调用 remove 方法时,将模型传递给它集合被刷新,我看不到已删除的模型,但在 IE9 中它不会刷新,直到我手动刷新页面。

当尝试在 IE9 中收集 console.log 时,我得到了 undefined。

在 IE10+ 和所有其他浏览器中,这可以正常工作。

我正在使用backbone.marionette和使用requirecs的coffeescript。

这里是示例:

delete: ->
  @deleteDeferred = $.Deferred()
  vent.trigger 'modal:', name: 'deleteConfirm', modalSize: '', model: @
  promise = @deleteDeferred.then =>
    xhr = $.ajax
      url: "/api/v1/user-contact-data/#{@id}"
      dataType: 'json'
      type: 'DELETE'

  promise.done =>
    @collection.remove(@) if @collection

  promise.always =>
    delete @deleteDeferred

  promise

对此有什么想法吗?

谢谢。

【问题讨论】:

  • 可以分享一下编译好的JavaScript吗?

标签: javascript internet-explorer backbone.js coffeescript marionette


【解决方案1】:

我只是好奇,当您可以直接在模型上使用 destroy 方法时,为什么还要创建一个 Promise 和 XHR 调用?例如:

# This will automatically call "/api/v1/user-contact-data/#{@id}", using the verb 
# DELETE, fire the appropriate events, 
# and remove it from any collection(s) the model is attached to
@model.destroy success: =>
    vent.trigger 'delete:successful'

【讨论】:

    【解决方案2】:

    听起来 IE9 正在缓存您的 ajax 请求(不好玩=/)

    试试这个:

    $.ajaxSetup({ cache: false });
    

    这将添加一个“缓存破坏器”查询参数(毫秒时间戳),并确保每个 ajax 请求都是唯一的。

    【讨论】:

      猜你喜欢
      • 2017-03-06
      • 2012-10-15
      • 1970-01-01
      • 1970-01-01
      • 2014-08-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多