gpt4 book ai didi

javascript - 如何在 jQuery UI 小部件中决定 _init 和 _create ?

转载 作者:行者123 更新时间:2023-12-03 21:33:37 25 4
gpt4 key购买 nike

我想我理解小部件定义中 _create_init 之间的区别(例如 this question ),但我仍然不确定 区分的目的_create()_init() 中包含哪些类型的设置任务?如果小部件作者选择了错误的部件,会出现什么问题?

最佳答案

来自:

Use _create to build and inject markup, bind events, etc. Place default functionality in _init(). The dialog widget, for example, provides an autoOpen parameter denoting whether or not the dialog should be open once the widget is initialized; a perfect spot for _init()!

另外:

The widget factory automatically fires the _create() and _init() methods during initialization, in that order. At first glance it appears that the effort is duplicated, but there is a sight difference between the two. Because the widget factory protects against multiple instantiations on the same element, _create() will be called a maximum of one time for each widget instance, whereas _init() will be called each time the widget is called without arguments...

如果作者使用 _init()_create()应该已经被编码了,结果将是 _init() 中的代码每个小部件实例化都会执行一次。

关于javascript - 如何在 jQuery UI 小部件中决定 _init 和 _create ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4566337/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com