-
-
Notifications
You must be signed in to change notification settings - Fork 363
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Trying to get comparisons working in an #each loop #247
Comments
Hmm, I would have thought that |
I added it in my else block and it outputs nothing. |
If it works outside of the block, that indicates that |
Oh sorry if it wasn't clear. :) The each works perfectly. The drop down shows every existing user. It is the comparison that is failing, it never matches and outputs selected where it should. |
Thanks for the clarification. Hmm.. with templates it's hard to debug without having the code in front of me, but what usually helps for me is to log out every variable, in every part of the loop, starting at the top. First, maybe try creating a custom log helper too (fwiw I've been meaning to push up changes to the existing log helper, because it logs out the handlebars options, which makes it hard to see what's happening). Something like: function log() {
var args = [].slice.call(arguments);
args.pop() // get rid of hbs options
console.log.apply(console, args);
} Then just log out all of the variables in each step and see where the comparison is breaking down: {{log "user" user}}
{{log "user._id" user._id}}
{{log "../user._id" ../user._id}}
{{log "@root.project.creator._id" @root.project.creator._id}}
<!-- here, I think "this" would be "user" since you're inside the each block, but I'm not sure -->
{{log "this.name" this.name}} It might be that the |
Would "is" be using === maybe? As it stands, I first tried comparison with ==, it didn't work either. |
Here is the code for is. It is doing |
Well in theory - both are Mongo ID values, but - I don't know. I'll keep logging and let you know (may be delayed - giving a presentation in a bit and wifi is horrible here) |
Hope this isn't holding up your presentation, anything I can do to help? |
Oh no - heh sorry - totally different worlds. (preso on Apache Cordova, this work is a side project) |
good! yeah let me know when/if you have more detail, happy to help. |
So given I'm adding all the helpers from the lib directly into my Handlebars instance, how do I append the custom log function above? Currently I've got:
|
nm - just added it to hlpers before passing it to handlebars |
The log helper helped a lot. This is now working:
Specifically: |
Great! I wonder why |
Nope, doesn't help. I assume you meant |
Either. It's odd that |
Yep. Maybe this is something that could be added to the docs? Or to a FAQ (don't know if one exists). Otherwise, just close it and thank you again! |
@cfjedimaster I'd be happy to, I'm not sure this was something related to this lib. I'm still confused as to why |
Someone get the answer of this? because i have the same problem!! |
For the life of me, I cannot get comparison, or if, to work inside an each loop. I'm currently trying this:
In my comparison, on the right hand side, I tried @root.user._id, user._id, and what you see above. Nothing seems to work.
By the way, I know the {{else}} branch is creating invalid HTML, but I'm just using it to try to debug.
The text was updated successfully, but these errors were encountered: