I am using Taffy DB, and have a search feature which searches for a property:

var finded = properties({type:"small"}).get();

finded.forEach( function() {
    var name = this['name'];
    alert('The matched result is ' + name + '.');
});

The the first returns two javascript objects, for both properties found.

The next section of code (line 3-) is supposed to perform a function on each object retrieved to get its 'Name' key and then post it in an alert box.

However, instead it just comes out blank. There isn't [object Object], there isn't undefined it's just blank (with the exception of the quoted text, of course.)

What am I doing wrong?

有帮助吗?

解决方案

this is not refer to an array or to the element of that array, instead if you don't provide second argument of Array.prototype.forEach, callback function will be executed in global context.

finded.forEach(function (value) {
    var name = value.name;
});
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top