I think I understand the difference between _create
and _init
in widget definitions (see for instance this question), but I'm still not certain about the purpose for the distinction. What sorts of setup tasks go in _create()
or in _init()
? What goes wrong if the widget author chooses the wrong one?
相关问题
- Is there a limit to how many levels you can nest i
- How to toggle on Order in ReactJS
- How to fix IE ClearType + jQuery opacity problem i
- void before promise syntax
- jQuery add and remove delay
From:
Also:
If the author uses
_init()
when_create()
should have been coded, the result will be that the code in_init()
will be executed once per widget instantiation.Short answer here: _create() will be executed when you run your jquery-ui plugin for the first time, like $xx.your-plugin(your options); _init() will be executed first and after the first time when your code runs into $xx.your-plugin(your options);
As there are some code in jquery-ui.custom.js like this:
So, if you draw a chart with jquery-ui plugin, after it's drawn out, then you want to use new data to update it, you need to do this in _init() to update your chart. If you just display something and won't update them totally, _create() will meet your needs.