In my coffeescript code, I am attempting to retrieve the keys from an object where the key matches a specific value. However, in addition to the object's own properties, I am also getting function properties in my result.
This issue is causing an error related to the 'track by' expression which does not exist on these function properties.
[ngRepeat:dupes]Duplicates in a repeater are not allowed. Use 'track by' expression to specify unique keys. Repeater:
, Duplicate key:prod in products | track by prod.ProductTypeCode
undefined
Here is the 'track by' expression that is triggering the error:
<option ng-repeat="prod in products | track by prod.ProductTypeCode"
value="{{prod.ProductTypeCode}}">{{prod.ProductType}}
</option>
Although I specified the 'own key' in the 'for of' loop, functions like 'isEmpty' and 'contains' are still appearing in my result array.
Here is the 'for of' loop I am using:
product for own key, product of $scope.products when key isnt 'RTMT'
Shown below is my $scope.Products
containing the keys:
{
CK: {
ProductCategoryCode: 'DEP',
ProductCategory: 'Deposit',
ProductTypeCode: 'CK'
},
RTMT: {
ProductCategoryCode: 'RTMT',
ProductCategory: 'Retirement',
ProductTypeCode: 'IRA'
},
SAV: {
ProductCategoryCode: 'DEP',
ProductCategory: 'Deposit',
ProductTypeCode: 'SAV'
},
TD: {
ProductCategoryCode: 'DEP',
ProductCategory: 'Deposit',
ProductTypeCode: 'TD'
}
}
While I am able to extract only 'CK', 'SAV', and 'TD', I am observing unexpected functions as well:
https://i.sstatic.net/KAvw8.png
How can I filter out the function types and only retrieve the Object types in coffeescript?
Upon examining the compiled JavaScript code snippet, it appears to work correctly but the functions are still visible in Firefox's debug window.
// Generated
var hasProp = {}.hasOwnProperty,
indexOf = [].indexOf || function(item) {
for (var i = 0, l = this.length; i < l; i++) {
if (i in this && this[i] === item) return i;
}
return -1;
};
var obj = {
CK: {
ProductCategoryCode: 'DEP',
ProductCategory: 'Deposit',
ProductTypeCode: 'CK'
},
RTMT: {
ProductCategoryCode: 'RTMT',
ProductCategory: 'Retirement',
ProductTypeCode: 'IRA'
},
SAV: {
ProductCategoryCode: 'DEP',
ProductCategory: 'Deposit',
ProductTypeCode: 'SAV'
},
TD: {
ProductCategoryCode: 'DEP',
ProductCategory: 'Deposit',
ProductTypeCode: 'TD'
}
};
console.log(getValues(obj));
function getValues(obj) {
// Generated
var key, product, ref, results;
ref = obj; // $scope.products;
results = [];
for (key in ref) {
if (!hasProp.call(ref, key)) continue;
product = ref[key];
if (key !== 'RTMT') {
results.push(product);
}
}
return results;
}