2016-03-07 71 views
0

我升級我的應用程序從.NET 4.0到4.5,從1.4.17升級到Breeze.js 1.5.4。事情似乎在IE11和其他瀏覽器運作良好,但在IE8(或IE11在IE8模式),我得到一個「對象不支持此屬性或方法」錯誤與在這部分代碼的_normalizeServiceName方法:對象不支持在IE8此屬性或方法:_normalizeServiceName

function updateWithConfig(obj, config) { 
    if (config) { 
    assertConfig(config) 
     .whereParam("serviceName").isOptional() 
     .whereParam("adapterName").isString().isOptional() 
     .whereParam("uriBuilderName").isString().isOptional() 
     .whereParam("hasServerMetadata").isBoolean().isOptional() 
     .whereParam("jsonResultsAdapter").isInstanceOf(JsonResultsAdapter).isOptional() 
     .whereParam("useJsonp").isBoolean().isOptional() 
     .applyAll(obj); 
    obj.serviceName = obj.serviceName && DataService._normalizeServiceName(obj.serviceName); // <<< Error here 
    obj.adapterInstance = obj.adapterName && __config.getAdapterInstance("dataService", obj.adapterName); 
    obj.uriBuilder = obj.uriBuilderName && __config.getAdapterInstance("uriBuilder", obj.uriBuilderName); 
    } 
    return obj; 
} 

我可以看到_normalizeServiceName方法被定義權updateWithConfig後:

ctor._normalizeServiceName = function (serviceName) { 
    serviceName = serviceName.trim(); 
    if (serviceName.substr(-1) !== "/") { 
    return serviceName + '/'; 
    } else { 
    return serviceName; 
    } 
}; 

如果我跟蹤過那裏DataService定義,ctor確實有返回時,它定義的_normalizeServiceName方法,而是通過時間updateWithConfig是稱爲從DataService丟失。

的錯誤,當我創建一個新的EntityManager發生:

this.manager = new breeze.EntityManager(appRoot + "breeze/myapp"); 

微風網站似乎是說,IE8仍然支持。我有條件註釋中引用了ES5 Shim/Sham腳本:

<!--[if lt IE 9]> 
<script src="/myapp/js/respond.js"></script> 
<script src="/myapp/js/es5-shim.js"></script> 
<script src="/myapp/js/es5-sham.js"></script> 
<script src="/myapp/js/json3.js"></script> 
<![endif]--> 

那麼,IE8仍然支持Breeze?我錯過了什麼,我需要在我的代碼更新從微風1.4.x中去1.5.x的(我唯一改變的事情是關係到Promise API似乎改變)時?或者這是微風中的一個錯誤?

回答

0

也許不是回答「不支持微風IE8」,但我想我會記錄我做了什麼,把事情弄好,如果它可以幫助別人。

的第一個問題是,IE8不喜歡命名的構造函數(如果這甚至正確的術語)在this commit to breeze.js介紹。要解決這個問題,我添加了一個步替換我gulpfile.js刪除函數名稱:

gulp.task("breeze", function() { 
    var js = gulp 
     .src(src.bower + "breeze-client/build/breeze.debug.js") 
     .pipe(replace(/var ctor = function (\w+)/g, "var ctor = function ")) 
     .pipe(rename("breeze.js")) 
     .pipe(gulp.dest(dest.js)); 
    return merge(js); 
}); 

而且,由於我使用的打字稿,爲微風目前的分型定義IPromise接口(在this commitQ.Promise改變,大概是爲了支持Angular),它使用IE8不喜歡的方法名稱(最終捕獲),並且沒有定義ES3友好的別名(失敗,fin)。我說我自己的定義,並且還定義將q done()方法:

declare module breeze.promises { 
    // IE8 (and other ES3 browsers?) don't like .catch and .finally 
    // Also define Q's .done method. 
    interface IPromise<T> { 
     done<U>(): IPromise<U>; 
     fail<U>(onRejected: (reason: any) => U): IPromise<U>; 
     fail<U>(onRejected: (reason: any) => IPromise<U>): IPromise<U>; 
     fin(finallyCallback:() => any): IPromise<T>; 
    } 
} 

最後,我已經更新ES5,墊片,以v4.5.7作爲我的升級,這似乎打破IE8太的一部分,雖然我沒有想法如何/爲什麼在這一刻。我不知道以前使用的是什麼版本(無法在.js文件中找到版本號),因爲很久以前我已經手動複製了它。我不得不一直回到v4.1.7來找到一個可以工作的版本,所以大概是v4.1.8中的一些東西會打破IE8。

有了這一切,事情似乎在IE8工作了!

相關問題