使用 ExtJS 进行多选

发布于 2024-10-07 01:14:26 字数 724 浏览 0 评论 0原文

我有一个带有下一个代码的表单:

<select multiple="multiple" id="something" class="boo" name="foo">
    <option value="40">AAAAA</option>
    <option value="39">BBBBB</option>
    <option value="15">CCCCC</option>
</select>

目前这个表单有一个绑定的 onChange 函数,它看起来像:

var updateValues = function(event, target, object){
     var selectbox = Ext.get(target.id);
     var values = [];
     for(i=0; i<selectbox.dom.options.length; i++){
         if (selectbox.dom.options[i].selected)
            {values.push(selectbox.dom.options[i].value);}
     }
     callSomeFunc(values);
}

我认为应该有一个函数,它返回选定值的数组,就像 jQuery 的 val()做。

I have a form with next code:

<select multiple="multiple" id="something" class="boo" name="foo">
    <option value="40">AAAAA</option>
    <option value="39">BBBBB</option>
    <option value="15">CCCCC</option>
</select>

Currently this form has a binded onChange function, which looks like:

var updateValues = function(event, target, object){
     var selectbox = Ext.get(target.id);
     var values = [];
     for(i=0; i<selectbox.dom.options.length; i++){
         if (selectbox.dom.options[i].selected)
            {values.push(selectbox.dom.options[i].value);}
     }
     callSomeFunc(values);
}

I think there should be a function, which returns an array of selected values, just like jQuery's val() does.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

∞梦里开花 2024-10-14 01:14:26

如果您想要多项选择与类似 ComboBox 的功能相结合,我建议使用 SuperBoxSelect 用户扩展。如果开箱即用的外观和感觉不适合您,您可以通过修改或删除包含的 CSS 轻松更改它。

该组件提供了检索所选值的绝佳方法。当用户选择值时,组件将记住这些值并将其存储在内部。相反,如果用户删除值,组件也会为您处理该状态。假设原始功能适合您,您所需要做的就是在准备好提交表单后调用方法来获取值。

如果您有兴趣,这里有一个演示页面。它很容易包含在您的 JavaScript 中,因此不必担心它是用户扩展:

http ://www.technomedia.co.uk/SuperBoxSelect/examplesRemote.html

If you want multiple selection combined with ComboBox-like functionality, I would recommend using the SuperBoxSelect user extension. If the out-of-the-box look and feel doesn't suit you, you can easily change it by modifying or removing the included CSS.

The component provides great methods to retrieve the selected values. As the user selects values the component will remember the values and store them internally. Conversely, if a user removes values the component will handle that state for you as well. All you need to do, assuming the original functionality suits you, is call the methods to get the values once you're ready to submit your form.

Here's a demo page if you're interested. It's very easy to include in your javascript, so don't worry that it's a user extension:

http://www.technomedia.co.uk/SuperBoxSelect/examplesRemote.html

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文