如何在 Selectable 控件中插入项目
是否有一种“干净”的方式在 jQuery UI Selectable 控件中插入项目?
比如说,我有以下可选:
<div id="selectable">
<div>Item 1</div>
<div>Item 2</div>
<div>Item 3</div>
</div>
我可以手动插入一行,例如:
$('<div>Item 4</div>').addClass('ui-selectee').appendTo($('#selectable'));
虽然它在视觉上看起来是正确的,但是否还需要包含任何事件?这是插入项目的干净方法,还是有更好的方法?
Is there a "clean" way to insert an item in a jQuery UI Selectable control?
Say, I have the following Selectable:
<div id="selectable">
<div>Item 1</div>
<div>Item 2</div>
<div>Item 3</div>
</div>
I could manually insert a row like:
$('<div>Item 4</div>').addClass('ui-selectee').appendTo($('#selectable'));
While it visually looks correct, is there any events I need to include as well? Is that a clean way to insert an item, or is there a better way?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
没有 api 可以做到这一点。所以我相信你的编码是正确的方法。您也可以尝试在添加后调用
.selectable( "refresh")
。There's no api for doing it. So I believe your coding is a correct way. You may also try to call the
.selectable( "refresh")
after addition.根据API,您也可以只使用选项autoRefresh(默认启用)在将元素添加到 DOM 元素时扩展可选择元素的列表。
如果您有大量元素列表,建议将 autoRefresh 设置为 false 并手动调用 refresh 方法。
According to the API you can also just use the option autoRefresh (enabled by default) to extend the list of selectable-elements as you add elements to the DOM-element.
If you have a huge list of elements it's recommended to set autoRefresh to false and call the method refresh manually.