Maybe I am doing this wrong and tips on ways to improve my code are appreciated. My situation is: I have various elements that have a callback. I do not want to use show () or hide () commands, I like to use separate, but I think it should be a good way to deal with it. Here is my code:
entryView = function_entryView () {var menu button = $ ('& lt; div / & gt;'). AddClass ('menubutton'); instrument panel (); $ .getJSON ('ajax', function (o) {var $ enum2 = ss.IEnumerator.getEnumerator (dto.TransmittalDates); while ($ enum2.moveNext ()) {var dateTime = $ enum2.get_current (); $ ( '.menu') .andend ($ ('& lt; div / & gt;') addClass ('menuitem'). Text (dateTime.toString ()));}}); } ToolBar = function _toolBar () {var flyoutMenu = $ ('& lt; div / & gt;') addClass ('menu'); $ ('Menu button'). Click (function (o) {$ ('.mainbutton'). Attachments (flyout menu);}); I have a quick cut and pasted and they have changed the name of the variable to understand them. As you can see at the entrance I create the toolbar and the last thing I am calling AJAX. The menu, however, is not created until the "click" event, so it is not possible to insert.
I know that because of the global variable being bad, I am trying to avoid it, but I think in the best case, AJAX calls will populate a menu variable and when DOM will be created How do I remove it from the same menu item? Is there a better way to do this?
Edit: Fit a bit on the toolbar function, I think I should have this right.
I'm confused with some parts of your code:
- What is the
entryViewfunction and when is it called? - Why is the
toolbarfunction present inline? Where is it called? -
Why are you building such a function? Creating a variable without
varis bad practice, always creates global variables, and ES5 will be denied in strict mode. You should work like this:var someFunction = function (arg1, arg2) {...};or like it:
Function Some functions (arg1, arg2) {...} - Why are you giving a different name to each function (like
_toolbar)? The name "private" will only be within the scope of the function.
The menu should not be in the global scope, in only one workspace, which is common for both functions.
I toolbar :
function entryView () {var menuButton = $ ('& lt; div / & gt; {'Class': 'menubutton'}), menu = $ ('& lt; div / & gt;', {'class': 'menu'}); $ .getJSON ('ajax', function (o) {var $ enum2 = ss.IEnumerator.getEnumerator (dto.TransmittalDates); while ($ enum2.moveNext ()) {var dateTime = $ enum2.get_current (); $ ( '.menu') .andend ($ ('
Comments
Post a Comment