EmberJS:设置仅在IE中绑定到视图的集合属性时出错

时间:2012-11-08 15:04:51

标签: javascript ember.js

我有一个ember对象,其collection属性绑定到模板。当我尝试像这样设置这个属性时:

processingJob.set("logMessages", updatedProcessingJob.logMessages)

我只在IE中获得此异常,所有其他浏览器都正常工作:

  

SCRIPT5022:断言失败:Ember.CollectionView的内容必须实现Ember.Array。您传递了[object Object],[object Object],[object Object]

它像这样绑定到模板:

{{#each content.logMessages}}
    {{#isWorkflowError}}
        <li class="error"><i class="icon-thumbs-down"></i> {{message}}</li>
    {{else}}
        <li><i class="icon-thumbs-up"></i> {{message}}</li>
    {{/isWorkflowError}}
{{/each}}

当我删除模板时,我没有收到错误。我应该使用Ember.CollectionView吗?或者这是一个IE错误?

1 个答案:

答案 0 :(得分:0)

我找到了解决此问题的方法并将其发布在此处:https://github.com/emberjs/ember.js/issues/1525

我正在使用SignalR将更新推送到我的ember应用程序,我的代码看起来像这样:

App.ProcessingJobArray = Ember.ArrayProxy.extend
    init: ->
        @set("content", Ember.A())
        if $.connection
            @client = $.connection.processingJobHub
            @client.processingJobUpdated = (updatedProcessingJob) =>                
                processingJob = @get("content").find((item) ->
                    item.get("id") == updatedProcessingJob.id
                )
                if not processingJob
                    processingJob = App.ProcessingJob.create()
                    @get("content").pushObject(processingJob)
                processingJob.setProperties(updatedProcessingJob)
            $.connection.hub.start()

updatedProcessingJob JSON对象包含一个数组logMessages,在IE中我收到一个错误,因为这个数组没有元哈希。为了解决这个问题,我做了一个updatedProcessingJob的深层副本:

updatedProcessingJob = $.extend(true, {}, updatedProcessingJob)