javascript - Meteor variable scope -


I know about the scope of What is the reality, so this meteor event is helpful to me:

  Template.test.events ({'click .selector': function (e) {e.preventDefault (); var someArray = [ 1,2, 3,4]; var Some variables = "jquery slector data"; console.log (some variables); // This work expects some range. Reed (function (index, L) {console.log (SomeVariable); // not defined?}}}})   

I was under the impression that any variable declared outside any of my ceremonies would be available inside it? Although I'm not being defined, is this a typical meteorite thing or javascript? Also, how can I access Val inside the .each function without making the global? I do not think my variable would be considered ideal within .each loop because this means that there will be many visits to the DOM.

Thank you.

The problem is that you try to use the each () method , Which is not present on Array.prototype . I believe you are looking for Array.prototype.forEach () underscore's _. Each (array, callback) method also works, and is more consistent with older browsers.

This should work:

  Template.test.events ({'click .selector': function (e) {e.preventDefault (); var someArray = [ 1,2,3,4]; var Some variables = "jquery slector data"; console.log (someVariable); someArray.forEach (function (val, indices) {console.log (someVariable);});}}) ;   

Or, for compatibility:

  _.each (some array, function (val, index) {console.log (some variables);})   

I believe your illusion of jQuery's $ Each () is linked to using the method, which is the native forEach and _.each () of the underscore. For one, jQuery has a different logic sequence (note that I have changed the order of the arguments in the code). Generally, I recommend using underscore for works related to collections and primarily use jQuery for DOM manipulation.

Comments

Popular posts from this blog

Java - Error: no suitable method found for add(int, java.lang.String) -

java - JPA TypedQuery: Parameter value element did not match expected type -

c++ - static template member variable has internal linkage but is not defined -