Conversation
…e view is not working.
Ada TraderWhat We're Looking For
|
| ]; | ||
|
|
||
| quoteData.forEach(function(quote) { | ||
| $('#dropdown').append(`<option>${quote.symbol}</option>`) |
There was a problem hiding this comment.
This code should really be within the $(document).ready(...) callback function.
The reason for that is because we're using jQuery to find the select tag on the page with ID dropdown, and then manipulating it by appending option tags inside of it. Both of these things are only guaranteed to work properly if we wait until the entire page has been loaded -- which is what the $(document).ready(...) is for.
We can see the problem manifest if we change index.html to have the script tag for app.bundle.js inside of the head tag after the meta tags, instead of at the bottom of the body tag. By moving the JS code to the top of our HTML file, the browser will load it and run the JS code in app.js first, before, loading the actual HTML content of the page.
In that case the drop down selection does not have any options added to it, because when this line of code runs jQuery cannot find the select tag with ID dropdown (because it hasn't been loaded yet from the HTML file).
| quoteList: quotes, | ||
| }); | ||
|
|
||
| const order = new Order({ |
There was a problem hiding this comment.
It doesn't look like this instance of Order is being used anywhere, so we could probably remove it?
| this.listenTo(this.model, 'update', this.render) | ||
|
|
||
| this.listenTo(this.bus, 'newOrder', this.addOrder); | ||
| this.listenTo(this.bus, 'newOrder', this.render); |
There was a problem hiding this comment.
In general it's totally okay to have multiple callbacks for a single event (this is especially useful when the callbacks are doing completely unrelated stuff), however in this case it's not necessary.
What will happen hear is that this.addOrder() will be called first when the newOrder event is triggered. When that method runs it calls this.model.add(), which puts the new order into the OrderList collection... which itself triggers the update event on the collection.
And we already have a listener for the update event which runs this.render(), so we're effectively calling this.render() twice. Once as a result of update and then again as a result of newOrder.
Ada Trader
Congratulations! You're submitting your assignment!
Comprehension Questions
Form error handling is not completely set up to appear in the DOM and all associated spec tests pass.