我的脚本在每个浏览器中都能完美运行,但即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;
}
}
})()
答案 0 :(得分:3)
您的语法
setcurrentList(list) {
在对象内部,仅在ES2015中有效,并且是所谓的方法定义,是在对象文字内声明函数的简便方法
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Method_definitions
方法定义在IE11中无效,应该是
setcurrentList: function(list) {
如果您必须支持旧浏览器(或任何版本的IE)