本文介绍了IE中的等价传播算子-Javascript的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个javascript函数来填充单个表格行的下拉列表,例如:
I have a javascript function to populate dropdowns for individual table rows like:
$scope.possibleOptions = getUniqueValues($scope.yypeOptions, 'yypeOption')
.map(function(id) {
return {
id: id,
name: id
});
function getUniqueValues(array, prop) {
return [...new Set(array.map(item => item[prop]))];
}
其中, $ scope.yypeOptions
是:
$scope.yypeOptions = [{
yypeOption: "option1"
}, {
yypeOption: "option2"
}];
我现在必须使其与IE兼容.我必须替换 spread
和 =>
运算符.
I now have to make it compatible to IE. The spread
and =>
operator is something I have to replace.
通过此和此链接.但是我对如何在数组功能内部替换Set一无所知.
Went through this and this link. But I could not get any understanding how to replace the Set inside an Array feature.
推荐答案
这是可以在IE上运行的简单方法
Here is a simple way that could work on IE
data =[{name:"a"}, {name:"a"},{name:"x"}]
function getUniqueValues(array, prop) {
return array.map(function(item) { return item[prop]; })
.filter(function (item, index, self){ return self.indexOf(item) === index; }); // distinct
}
console.log(getUniqueValues(data, "name"))
这篇关于IE中的等价传播算子-Javascript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!