如何在jQuery UI小部件中决定_init和_create? [英] How to decide between _init and _create in jQuery UI widget?

查看:133
本文介绍了如何在jQuery UI小部件中决定_init和_create?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想我理解小部件定义中 _create _init 之间的区别(例如参见这个问题),但我仍然不确定目的区别。什么类型的设置任务进入 _create() _init()?如果小部件作者选择了错误的,会出现什么问题?

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?

推荐答案

来自:

  • http://forum.jquery.com/topic/jquery-ui-1-8-use-of-init
  • http://www.erichynds.com/jquery/tips-for-developing-jquery-ui-widgets/
  • http://jqueryui.com/demos/dialog/

使用 _create 构建并注入
标记,绑定事件等。放置
_init()中的默认功能。
对话框小部件,例如
,提供 autoOpen 参数
表示对话框
是否应该打开一次小部件是
初始化;
的理想位置 _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()!

另外:


小部件工厂自动触发
_create() _init()方法
在初始化期间按此顺序排列。
乍一看似乎
的努力是重复的,但两者之间存在
的视线差异。
因为小部件工厂保护
免受
相同元素上的多个实例化, _create()将被称为
最大值每个
小部件实例一次,而 _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()中的代码。

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.

这篇关于如何在jQuery UI小部件中决定_init和_create?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆