我创建了什么,我想你想在http://telliott.net/dojoExamples/dojo-fancyRadioButtons.html
这里有延伸彼得自定义部件的例子Higgins的widgets中的小部件示例来自http://higginsforpresident.net/2010/01/widgets-within-widgets。我已经为我的代码重新命名了基本小部件'telliott.Widget'。
要创建“RadioContainer”,你叫
<script type="text/javascript">
dojo.require('telliott.RadioContainer');
dojo.addOnLoad(function() {
var container1 = new telliott.RadioContainer({
id: 'Container1',
name: 'Container1',
labels: ['one', 'two', 'three', 'The quick brown fox', 'Jumped over the lazy dog', 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.', 'Mauris vitae nunc non risus commodo sodales', 'Maecenas sed nibh et turpis laoreet volutpat at et sapien'],
selected: 'two',
}).placeAt(dojo.byId('container'));
});
</script>
的RadioContainer
有一些JS代码(很明显,你可以提前从XHR电话或任何创建标签的数组):
dojo.provide('telliott.RadioContainer');
dojo.require('telliott.Widget');
dojo.require('dijit.form.RadioButton');
dojo.declare('telliott.RadioContainer', [telliott.Widget], {
templateString: dojo.cache('telliott', 'templates/RadioContainer.html'),
name: "",
postCreate: function() {
this.labels = this.labels || [];
this.name = this.name || "";
this.selected = this.selected || "";
this.labels.forEach(dojo.hitch(this, function(l) {
this.createRadio(l);
}));
},
createRadio: function(/* String */ label) {
var item = dojo.create('li', null, this.containerNode, 'last');
var nobr = dojo.create('nobr', null, item);
var radio = this.adopt(dijit.form.RadioButton, {
checked: this.selected == label ? true : false,
value: label,
name: this.name
});
radio.placeAt(nobr);
this.createLabel(label, radio.get('id'), nobr);
},
createLabel: function(/* String */ label, /* String */ idFor, /* Node */ location) {
dojo.create('label', { for: idFor, innerHTML: label }, location, 'last');
}
});
和模板:
<div class="dijit dijitReset RadioContainer">
<ul dojoAttachPoint="containerNode" class="dijit dijitReset contents"></ul>
</div>
一些CSS一起:
.claro .RadioContainer {
overflow-y: auto;
height: 100%;
}
.claro .RadioContainer .contents {
padding: 10px;
list-style: none;
}
当您创建的小部件本身,则应同时指定它的每个实例的宽度使用标准的CSS,即:
#Container1 {
width: 500px;
background-color: white;
}
内部,小部件仅仅是创建一个无序列表,将单选按钮和标签包裹在<nobr>
标记中,并将其添加为列表中的项目。
如果这是你想要的,让这个数据存储器知道是相当简单的。
非常感谢,谢谢! – 2011-03-02 21:53:46