我的脚本在所有浏览器中都可以完美运行,但是11(当然也就是...)。想不通我还能做什么。 JS Lint正在传递我的脚本...说它缺少冒号。这是整个功能。谢谢您的任何见解。在以“ setcurrentList(list) {”开头(倒数第二个功能)的行上发生错误。

编辑:更新的代码现在在上一个功能上收到错误:getcurrentList()

JQ

 generateAllLocationsData = (function() {
        var counter = 0;
        if (typeof allLocationsData == "undefined") {
            allLocationsData = [];
            for (var x = 0; x < officesData.children.length; x++) {
                for (var y = 0; y < officesData.children[x].departments.length; y++) {
                    if (officesData.children[x].departments[y].jobs.length > 0) {
                        for (z = 0; z < officesData.children[x].departments[y].jobs.length; z++) {
                            counter++;
                            ids.push(officesData.children[x].departments[y].jobs[z].id);
                            g_deptHolder[officesData.children[x].departments[y].jobs[z].id] = officesData.children[x].departments[y].name;
                        }
                    }
                }
            }
            jobsData = jobsData.sort(function(a, b) {
                if (a.title > b.title) {
                    return 1;
                }
                if (a.title < b.title) {
                    return -1
                }
                return 0;
            });
            for (var x = 0; x < jobsData.length; x++) {
                var dept = g_deptHolder[jobsData[x].id]
                if (typeof officesData["All Departments"][dept] == "undefined") {
                    officesData["All Departments"][dept] = [];
                }
                officesData["All Departments"][dept].push(jobsData[x]);
            }
            var sortedObject = [];
            Object.keys(officesData["All Departments"]).sort().forEach(function(key) {
                sortedObject[key] = officesData["All Departments"][key];
            })
            officesData.children = officesData.children.sort(function(a, b) {
                if (a.name > b.name) {
                    return 1;
                }
                if (a.name < b.name) {
                    return -1
                }
                return 0;
            })
            officesData["All Departments"] = sortedObject;
        }
        console.log("sorted", officesData);
        return officesData;
    });
    return {
        isLoading: function() {
            return (!jobsDataLoading && !officesDataLoaidng) ? false : true;
        },
        getJobsData: function() {
            if (this.isLoading() == false) {
                return officesData;
            } else {
                return false;
            }
        },
        getOfficesData: function() {
            if (this.isLoading() == false) {
                return officesData;
            } else {
                return false;
            }
        },
        getAllLocationsData: function() {
            return generateAllLocationsData();
        },
        setcurrentList: function(list) {
            this.currentList = list.sort(function(a, b) {
                if (a.title < b.title) {
                    return -1;
                }
                if (a.title > b.title) {
                    return 1;
                }
                return 0;
            });
        },
        getcurrentList(): function(list) {
            return this.currentList;
        }
    }
})()

最佳答案

您的语法

setcurrentList(list) {


在对象内部,仅在ES2015中有效,这就是所谓的方法定义,是在对象常量中声明函数的一种简便方法

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Method_definitions

方法定义在IE11中无效,应该是

setcurrentList: function(list) {


如果您必须支持旧版浏览器(或任何版本的IE)

10-06 04:42