English 中文(简体)
Dojo 中含有丰富选项的列表框
原标题:Listbox with rich options in dojo
  • 时间:2012-05-27 11:22:44
  •  标签:
  • dojo
  • listbox

我想知道是否有办法在 Dojo 获得一个列表框, 哪些选项由图像加上一段文字组成。 列表应产生类似的结果 :

listbox: - image/icon1 + text1 - image/icon2 + text2 ... - image/iconN + textN

我用一个下调列表来完成它,但这不是我需要的。我必须是列表框。

提前感谢。

问题回答

您可以使用已检查的 dojo MultiSweet 。

<select name="someName" id="someId" multiple="true" data-dojotype="dojox.form.CheckedMultiSelect">
   <option id="someOptionId"><img src="images/aim-icon.gif" border=0>Blah Blah</option>
</select> 

最后,我必须这样做:

<html>
<head></head>
<body>
    <select id="list" size="3" style="width:100px;"></select>
    <input id="clear" type="button" value="Clear">
    <input id="populate" type="button" value="Populate">
    <script type="text/javascript" src="dojo.js"></script>
    <script>
        dojo.addOnLoad( function(){
            dojo.connect( dojo.byId("clear"), "onclick", this, clear );
            dojo.connect( dojo.byId("populate"), "onclick", this, populate);
        });
        dojo.addOnLoad( populate );

        function populate(){
            for(var i = 0; i < 10; i++ ){
                var html = i%2 ?  <img src="image1.png"> Item   + i :
                                  <img src="image2.png"> Item   + i;
                dojo.create("option", {innerHTML: html, value: i },  list  );
            }
            dojo.byId( populate ).disabled = true;
            dojo.byId( clear ).disabled = false;
        }

        function clear(){
            var list = dojo.byId("list");
            var ops = list.options;
            while( ops.length ){
                ops.remove(0);              
            }
            dojo.byId( populate ).disabled = false;
            dojo.byId( clear ).disabled = true;
        }
    </script>
</body>
</html>

我希望它能帮上忙!





相关问题
WPF: How to limit number of rows shown by ListBox?

Is it possible to limit the number of rows a listbox show? Eg. let´s say I have a ItemSource with 100 items, but I only want my listbox to be 10 items high.

ListBox Value containing links

hi I am currently working on improving the SEO on a website containing dropdown list menu. currently when you select options and then submit a javascript is redirecting you to the next page I heard ...

asp.net listbox double click event + event handler

I am trying to add a double-click event in a listbox. But I am getting the following error. the aspx file <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="ListBox__Test.aspx.cs" ...

How to insert ComboBox item into ListBox? [winforms]

The question is very simple, How to insert ComboBox selected item into ListBox using c#? I have tried with this: listbox.Items.Add(combobox.SelectedItem); and some other permutations but it always ...

listbox itemtemplate for selected item

I am using Listbox with ItemTemplate, and when I select an item from the list, it shows blue background How can I style the selected item, to be similar to non-selected one?

WPF Data Binding Error in ListBox

I have a ListBox: <ListBox x:Name="HistogramListBox" Grid.Column="1" Margin="8,2,8,0" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Template="{StaticResource ...

How do I anchor an expander to right side of a ListBox?

The XAML code below works fine except I want the expander button to be between the listbox and the grid. If I set the ExpandDirection="Left" the button is between the listbox and the grid but the ...

Adding Items to ListBox, RadioList, Combobox using reflection

I m trying to add items to a listbox,combobox, radiolist using reflection. The code I have at the moment is as follows: public static Control ConfigureControl(Control control, ControlConfig ctrlconf)...

热门标签