I have j/s in my theme (am I infamous yet? ;) which is modifying the DOM by adding elements via api.decorateCooked(…. It inserts a variety HTML head elements.
I also have the DiscoTOC Theme component installed.
However, adding the usual <div data-theme-toc="true"> </div> that DiscoTOC notices and expands, doesn’t generate a table-of-contents including my dynamically inserted elements.
I’m figuring this might be as simple as execution order… if DiscoTOC looks before my j/s adds more elements . . .
What determines the ordering of execution if multiple bits of theme j/s code are calling api.cooked(?
I’m inserting within the post, yes. That’s why I suspect execution order.
Some bit of code determines the execution order… that’s the leverage point for me to get my component before TOC. eg, if it’s alpha by component name (ie, as displayed in the Component list in Admin area) then I can try namin my component accordingly, etc
That said, you can set initializer order for advanced use cases. I can put DiscoTOC in a named initializer so you can run your code before DiscoTOC, but I need to know what you’re trying to do first to give you a clear answer.
Your modifications here are based on an HTTP/AJAX request, correct?
Yes AJAX, but using a synchronous call. (I’ve always loved the oxymoron of synchronous AJAX :^)
I’m feeling like my next step is create a proper component—atm, it’s just some j/s pasted into my Theme’s Header. Then I can try fiddling with a judiciously chosen ID. “_foo” or “0-foo” might be all I need.
正如 @Johani 在上面提到的,如果您需要在使用其他组件加载后运行代码,最好的方法可能是使用 Ember initializer,它支持排序。不幸的是,在这种情况下,这可能无法立即实现,因为 DiscoTOC 似乎没有使用 Ember initializer。将 DiscoTOC 更新为使用多文件 JavaScript(因此是 Ember initializer)当然是 #pr-welcome。