如何从选择的组合菜单中获取对象...?我试过 e.target.getMenu().getModel()
</html>
<head>
<title>goog.ui.ComboBox</title>
<script src="closure-library/closure/goog/base.js"></script>
<script>
goog.require('goog.events');
goog.require('goog.ui.ComboBox');
goog.require('goog.dispose');
goog.require('goog.dom');
var test;
</script>
<style>
html, body {
overflow:hidden;
margin: 0;
padding: 5px;
}
#c {
margin-bottom: 10px;
font-size: small;
}
/* Size the combobox so that it is sufficiently small to demonstrate the menu
being positioned to left-align with the control. */
.goog-combobox input {
width: 100px;
}
fieldset {
display: inline-block;
margin: 10px;
text-align: initial;
}
</style>
</head>
<body>
<div id="c">cb.value = '<span id="v"></span>'</div>
<fieldset style="float:left">
<legend>LTR</legend>
<div class="combo"></div>
</fieldset>
<script type="text/javascript">
function createTestComboBox() {
var cb = new goog.ui.ComboBox();
cb.setUseDropdownArrow(true);
cb.setDefaultText('Select a folder...');
cb.addItem(new goog.ui.ComboBoxItem('Inbox',{"a":1}));
cb.addItem(new goog.ui.ComboBoxItem('Bills & statements',{"b":2}));
cb.addItem(new goog.ui.ComboBoxItem('Cal alumni',{"c":3}));
cb.addItem(new goog.ui.ComboBoxItem('Calendar Stuff',{"d":4}));
cb.addItem(new goog.ui.ComboBoxItem('Design',{"e":5}));
cb.addItem(new goog.ui.ComboBoxItem('Music',{"f":6}));
cb.addItem(new goog.ui.ComboBoxItem('Netflix',{"g":7}));
cb.addItem(new goog.ui.ComboBoxItem('Personal',{"h":8}));
cb.addItem(new goog.ui.ComboBoxItem('Photos',{"i":9}));
cb.addItem(new goog.ui.ComboBoxItem('Programming languages',{"j":10}));
return cb;
}
var controls = [];
var containerEls = goog.dom.getElementsByClass(goog.getCssName('combo'));
for (var i = 0; i < containerEls.length; i++) {
var cb = createTestComboBox();
cb.render(containerEls[i]);
goog.events.listen(cb, 'change', handleChangeEvent);
controls.push(cb);
}
function handleChangeEvent(e) {
test=e;
goog.dom.setTextContent(document.getElementById('v'), e.target.getValue());
}
window.onbeforeunload = function() {
goog.disposeAll(controls);
};
</script>
</body>
</html>