为什么只渲染数组,但是对它进行ng-repeat失败?

时间:2013-08-28 15:26:41

标签: javascript angularjs angularjs-ng-repeat

第一个版本有效,第二个版本失败 Uncaught Error: 10 $digest() iterations reached. Aborting!

<table data-role="parsed config viewer">
    <thead>
        <tr>
            <th>name</th>
            <th>client strings</th>
            <th></th>
        </tr>
    </thead>
    <tbody>
        <tr ng-repeat="svc in services">
            <td>{{svc.name}}</td>
            <td>{{svc.remoteClients()}}</td>
            <td>
                <button ng-click="getJson('http://'+nodeHost+'/parsed.config?host='+sandbox+'&base='+machineBasePath+case+'&path='+svc.dir+'Web.config',svc,false);">Refresh</button>
            </td>
        </tr>
        <tr ng-repeat="svc in services">
            <td>{{svc.name}}(local)</td>
            <td>
                <ul>
                    <li ng-repeat="slClient in svc.localClients()">{{slClient}}</li>
                </ul>
            </td>
            <td>
                <button ng-click="getJson('http://'+nodeHost+'/parsed.config?host=localhost&base='+localpath+'&path='+svc.dir+'Web.config',svc,true);">Refresh</button>
            </td>
        </tr>
    </tbody>
</table>

javascript

if (!Array.prototype.arrayFirst) {
    Array.prototype.arrayFirst = function (predicate, predicateOwner) {
        var array = this || [];
        for (var i = 0, j = array.length; i < j; i++)
        if (predicate.call(predicateOwner, array[i])) return array[i];
        return null;
    };
}
if (!Array.prototype.arrayMap) {
    Array.prototype.arrayMap = function (mapping) {
        var array = this || [];
        var result = [];
        for (var i = 0, j = array.length; i < j; i++)
        result.push(mapping(array[i]));
        return result;
    };
}
var Service = function (name, path, svc, notes) {
    var self = this;
    this.name = name;
    this.path = path;
    this.svc = svc;
    this.notes = notes;
    this.dir = "\\" + path.replace("/", "\\") + "\\";
    this.url = "/" + path.replace("\\", "/") + "/" + svc;

    var getConfig = function (local) {
        var parsed = local ? self.parsedlocal : self.parsed;
        return parsed;
    };

    var getClients = function (local) {
        var parsed = getConfig(local);
        if (!parsed) return ["not attempted"];
        if (!parsed.configuration) return ["no configuration"];
        if (!parsed.configuration['system.serviceModel']) return ["No Service Model"];
        var clients = parsed.configuration['system.serviceModel'][0].
        client[0].endpoint.arrayMap(function (a) {
            return {
                name: a.$.name,
                address: a.$.address
            };
        });

        return clients;
    };
    this.localClients = function () {
        console.log('getting local clients');
        return getClients(true);
    };
    this.remoteClients = function () {
        console.log('getting remote clients');
        return getClients(false);
    };
};
var PublishCtrl = function ($scope, $http, $timeout) {
    window.publishCtrl = $scope;
    $scope.getJson = function (uri, svc, local) {
        console.log('get json!');

        //window.parsed= data;
        if (local) {
            var newParsed = {
                configuration: {
                    'system.serviceModel': [{
                        client: [{
                            endpoint: [{
                                $: {
                                    name: 'localabc'
                                }
                            }, {
                                $: {
                                    name: 'localcba'
                                }
                            }]
                        }]
                    }]
                }
            };
            if (newParsed != svc.parsedLocal) {
                console.log('updating parsedlocal');
                svc.parsedlocal = newParsed;
            }
        } else {
            console.log('updating parsed');
            svc.parsed = {
                configuration: {
                    'system.serviceModel': [{
                        client: [{
                            endpoint: [{
                                $: {
                                    name: 'remoteabc'
                                }
                            }, {
                                $: {
                                    name: 'remotecba'
                                }
                            }]
                        }]
                    }]
                }
            };
        }

    };
    $scope.services = [
    new Service("Wcf Portal", "Services.Host", "WcfPortal.svc"),
    new Service("Registration Portal", "Services.Host.Registration", "WcfPortal.svc"),
    new Service("Program Pricing", "Services.Host.ProgramPricing", "ProgramPricingService.svc"),
    new Service("Data Lookup", "DataLookupService", "DataLookupService.svc", "path depth issues"),
    new Service("DocumentPrintingService", "Services.Host.PrintingService", "DocumentPrintingService.svc")];
};

http://jsfiddle.net/Maslow/j9Jes/

0 个答案:

没有答案
相关问题