【问题标题】:Breeze and Angular 'ToDo' app does not work with IE 8Breeze 和 Angular 'ToDo' 应用程序不适用于 IE 8
【发布时间】:2013-01-09 15:02:11
【问题描述】:

我已经从http://www.breezejs.com/documentation/download下载了示例“Breeze 0.83.5”应用程序

Angular 'ToDo' 示例不适用于 IE8。

我在 Breeze 脚本参考上方包含以下脚本参考。

知道为什么这不起作用吗?

【问题讨论】:

    标签: angularjs internet-explorer-8 breeze defineproperty


    【解决方案1】:

    Breeze 的 Angular 支持利用了“backingStoreAdapter”,而后者又依赖于浏览器实现的 ES5 Javascript 的“defineProperty”方法。这在 IE8 中没有实现,不幸的是,不能通过使用 shim 来补充。

    这是唯一有此限制的适配器,微风淘汰赛和骨干适配器,都可以在 IE8 上使用 ES5 垫片。

    对不起!

    【讨论】:

    • 嗨,Jay,知道它是否会在未来的版本中得到纠正吗?我们需要支持 IE8,Angular 本身在 IE8 中运行没有问题。谢谢。
    • 我们已经看过它,但不太确定如何在没有“defineProperty”的情况下轻松实现我们需要的内部更改通知。 Angular 的监视功能出现得太晚,我们无法使用它(我认为)。但是……请将此项目添加到微风用户的声音中(并投票)。还可以看看微风的 backingStore 实现,如果你能想出另一种实现它的方法,请告诉我。这很令人沮丧,我知道,因为 Angular 在现代浏览器上的微风确实能很好地工作。
    • 嘿,Jay... Breeze 的工作很棒!多么了不起的“一块”软件。恭喜它让我们所有人都可以使用。关于 IE 8 支持:看起来这里合并了一个修复:github.com/es-shims/es5-shim/issues/5 有了这个 shim 修复,您认为在 IE 8 上同时使用 Angular 和 Breeze 是否可行?
    • 我们将跟进您的建议,@LenielMacaferi。这似乎好得令人难以置信。我们会找出答案的。
    • @Ward:太好了!让我们希望修复确实增加了必要的支持。
    【解决方案2】:

    Breeze 的未来版本中,它也不会在 IE8 上工作。

    Todo-Angular 在现代浏览器中运行,例如 IE9、IE10 和最近的浏览器 Chrome、Safari、Firefox 和 WebKit 浏览器。微风不支持 在缺少 ECMAScript 5 的旧浏览器中运行的 AngularJS 应用程序 属性获取器和设置器。

    【讨论】:

    • 不确定您所说的不使用未来版本是什么意思。我们现在在最新的 Firefox、Chrome 和 IE 上进行测试。 backingStore 适配器在所有三个上都可以正常工作。你有没有没有的案例?
    • 抱歉含糊不清。我的意思是,即使在 Breeze 的未来版本中,它也无法在 IE8 上运行,因为正如您已经说过的,在 IE8 中无法填充 defineProperty。我会相应地更新我的答案。
    【解决方案3】:

    Breeze 使用托管 MVVM 框架的 ViewModel。这通常是一个不错的决定。此外,对实体的更改跟踪是微风.js 的一个基本概念(对于实体框架也是如此)。如果 MVVM 框架使用带有真正 getter 和 setter 的 Observables(例如 Knockout),跟踪更改是一件容易的事。另一方面,AngularJS 与普通的 JavaScript 对象一起工作。这使得变更跟踪变得困难。唯一可靠的两种方法是 ES5 属性(简单,但 IE8 不支持)或在 $digest 循环中非常深入的集成。微风团队选择了第一选择——对于必须支持 IE8 的项目来说真是太可惜了!

    好的,我们来分析一下问题的根源:变更跟踪

    你真的需要那个功能吗?至少在我们的项目中,我们决定使用breeze.js/OData 进行阅读,并在编写时采用更“宁静”的方法。如果您不需要这些高级功能,那么以下脚本应该可以解决问题:

    /********************************************************
     * A replacement for the "backingStore" modelLibrary
     * 
     * This is a bare version of the original backingStore,
     * without ANY change tracking - that's why it will work in IE8!
     * (Object.defineProperty not required any more)
     *
     * This adapter is a "drop in" replacement for the "backingStore" adapter in Breeze core.
     * It has the same adapter name so it will silently replace the original "backingStore" adapter
     * when you load this script AFTER the breeze library.
     * WARNING: For obvious reasons a lot of breeze magic will be lost!
     *
     * Author: Johannes Hoppe / haushoppe-its.de
     *
     * Copyright 2014 IdeaBlade, Inc.  All Rights Reserved.  
     * Use, reproduction, distribution, and modification of this code is subject to the terms and 
     * conditions of the IdeaBlade Breeze license, available at http://www.breezejs.com/license
     ******************************************************/
    
    (function (definition, window) {
        if (window.breeze) {
            definition(window.breeze);
        } else if (typeof require === "function" && typeof exports === "object" && typeof module === "object") {
            // CommonJS or Node
            var b = require('breeze');
            definition(b);
        } else if (typeof define === "function" && define["amd"] && !window.breeze) {
            // Requirejs / AMD 
            define(['breeze'], definition);
        } else {
            throw new Error("Can't find breeze");
        }
    }(function (breeze) {
        "use strict";
    
        var core = breeze.core;
    
        var ctor = function () {
            this.name = "backingStore";
            this.A_BIG_FAT_WARNING = "This is a bare version of the backingStore! Change tracking won't work!";
        };
    
        var protoFn = ctor.prototype;
    
        protoFn.initialize = function() {
    
        };
    
        protoFn.getTrackablePropertyNames = function (entity) {
            var names = [];
            for (var p in entity) {
                if (p === "entityType") continue;
                if (p === "_$typeName") continue;
    
                var val = entity[p];
                if (!core.isFunction(val)) {
                    names.push(p);
                }
            }
            return names;
        };
    
        protoFn.initializeEntityPrototype = function (proto) {
    
            proto.getProperty = function (propertyName) {
                return this[propertyName];
            };
    
            proto.setProperty = function (propertyName, value) {
                this[propertyName] = value;
                return this;
            };
        };
    
        // This method is called when an EntityAspect is first created - this will occur as part of the entityType.createEntity call.
        // which can be called either directly or via standard query materialization
        // entity is either an entity or a complexObject
        protoFn.startTracking = function (entity, proto) {
    
            // assign default values to the entity
            var stype = entity.entityType || entity.complexType;
            stype.getProperties().forEach(function (prop) {
    
                var propName = prop.name;
                var val = entity[propName];
    
                if (prop.isDataProperty) {
                    if (prop.isComplexProperty) {
                        if (prop.isScalar) {
                            val = prop.dataType._createInstanceCore(entity, prop);
                        } else {
                            val = breeze.makeComplexArray([], entity, prop);
                        }
                    } else if (!prop.isScalar) {
                        val = breeze.makePrimitiveArray([], entity, prop);
                    } else if (val === undefined) {
                        val = prop.defaultValue;
                    }
    
                } else if (prop.isNavigationProperty) {
                    if (val !== undefined) {
                        throw new Error("Cannot assign a navigation property in an entity ctor.: " + prop.Name);
                    }
                    if (prop.isScalar) {
                        // TODO: change this to nullstob later.
                        val = null;
                    } else {
                        val = breeze.makeRelationArray([], entity, prop);
                    }
                } else {
                    throw new Error("unknown property: " + propName);
                }
                entity[propName] = val;
            });
        };
    
        breeze.config.registerAdapter("modelLibrary", ctor);
    }, this));
    

    下载地址:https://gist.github.com/JohannesHoppe/72d7916aeb08897bd256

    这是原始 backingStore 的裸版,没有任何更改跟踪 - 这就是它可以在 IE8 中工作的原因! (不再需要 Object.defineProperty)此适配器是 Breeze 核心中“backingStore”适配器的“插入式”替代品。它具有相同的适配器名称,因此当您在微风库之后加载脚本时,它将默默地替换原始的“backingStore”适配器。

    这是一个演示功能的演示:
    http://jsfiddle.net/Johannes_Hoppe/bcav9hzL/5/

    JsFiddle不支持IE8,请直接使用这个链接:
    http://jsfiddle.net/Johannes_Hoppe/bcav9hzL/5/embedded/result/

    干杯!

    【讨论】:

      猜你喜欢
      • 2019-02-13
      • 1970-01-01
      • 1970-01-01
      • 2013-06-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-04-13
      • 1970-01-01
      相关资源
      最近更新 更多