IE9中的骨干收集错误

时间:2013-10-29 23:10:40

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

无法理解问题所在。

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

在IE9中尝试console.log集合时,我得到了未定义。

在IE10 +和所有其他浏览器中,这可以毫无问题地工作。

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

以下是样本:

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

有关于此的任何想法吗?

感谢。

2 个答案:

答案 0 :(得分:1)

听起来IE9正在缓存你的ajax请求(没有乐趣= /)

试试这个:

$.ajaxSetup({ cache: false });

这将添加“cache buster”查询参数(ms时间戳),并确保每个ajax请求都是唯一的。

答案 1 :(得分:0)

我只是好奇为什么你可以直接在模型上使用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'