有人可以帮助我吗?(对不起我的英语,我是法国人)我有一个组合框,我想在读取组合框中填充的数据数组之前插入一个项目“add-item”。总结一下 :
1-添加到我的组合框“add-item”(在读取数组之前添加),
2- 从我的数组中添加到我的组合框数据(这部分没问题)。
这是我的代码:
<h3>What would you like for breakfast?</h3>
<div id="bAutoComplete">
<input id="bInput" type="text"> <span id="toggleB"></span>
<div id="bContainer"></div>
<input id="myHidden" type="hidden">
</div>
<script type="text/javascript" src="assets/datafab.js"></script>
YAHOO.namespace("example.container");
YAHOO.example.Combobox = function() {
// Instantiate DataSources
var bDS = new YAHOO.util.LocalDataSource(YAHOO.example.Data.menu.breakfasts);
// Optional to define fields for single-dimensional array
bDS.responseSchema = {fields : ["name"]};
// Instantiate AutoCompletes
var oConfigs = {
prehighlightClassName: "yui-ac-prehighlight",
useShadow: true,
queryDelay: 0,
minQueryLength: 0,
animVert: .01
}
var bAC = new YAHOO.widget.AutoComplete("bInput", "bContainer", bDS, oConfigs);
bAC.resultTypeList = false;
// Breakfast combobox
var bToggler = YAHOO.util.Dom.get("toggleB");
var oPushButtonB = new YAHOO.widget.Button({container:bToggler});
var toggleB = function(e) {
//YAHOO.util.Event.stopEvent(e);
if(!YAHOO.util.Dom.hasClass(bToggler, "open")) {
YAHOO.util.Dom.addClass(bToggler, "open")
}
// Is open
if(bAC.isContainerOpen()) {
bAC.collapseContainer();
}
// Is closed
else {
bAC.getInputEl().focus(); // Needed to keep widget active
setTimeout(function() { // For IE
bAC.sendQuery("");
},0);
}
}
oPushButtonB.on("click", toggleB);
bAC.containerCollapseEvent.subscribe(function(){YAHOO.util.Dom.removeClass(bToggler, "open")
});
我的数组数据源来自datafab.js(我们有:甜甜圈,酸奶,......),所以我需要在这个列表之前添加项目“add-item”。项目“add-item”不应该在数组 datafab.js 中是否可以使用 yui 函数?