i have a condition in my function . i want to set a value of a variable true or false on the basis of another variable whether it is empty of not in knockout js?
self.editData = function (data) {
self.id(data.id());
self.nscto(data.nscto());
if (nscto != null && "".equals(nscto)){
self.view(true)
}
}
here i write if condition as we use in java language i want to use this scenarion in knockout how can i do it ?
The way you have it written you would need
There are many ways to do what you want:
or
or simpler
You have used two different variables (
nsct
andnsc
) and an operator that doesn't exist (=!
). The last part of the condition would be interpreted as an assignment:nsc = (!"")
.Also, the logic is wrong, there is no value that is null and an empty string at the same time, so the condition would always be true. You would use the
&&
operator instead:If you want to set it to false if the condition isn't true, then you would use an
else
also:You can also do that by using the value of the condition: