Closed shivrajsa closed 8 years ago
I get suggestions from only one object which was selected first time as per condition
It is because the condition
argument is in closure. In other words, the condition
is fixed when you execute the autoComplete
function and never change.
You can fix the problem by moving the condition
from function argument to outer variable.
var condition;
function autoComplete() {
...
$('..').textcomplete([{
template: function (word) {
if (condition) {
return word + '...';
} else {
...
}
}
}])
}
Thank you, its working now :-)
Based on some condition I want to display different suggestions, please refer below code, where if condition is 0 I want to use obj1 else if it is 1 then I want to use obj2.
But below code is not working as expected, every time I get suggestions from only one object which was selected first time as per condition. Please help to solve the problem