내 select
안에 options
을 보관할 캐시를 설정합니다. 그리고 select
에서 options
을 필터링하는 대신 select
을 지우고 일치하는 options
으로 다시 채 웁니다.
의사 코드의 풍부한 맛 :
onLoad:
set cache
onKeyPress:
clear select-element
find option-elements in cache
put found option-elements into select-element
는 여기에 내가 함께 선택의 무리를 체인 다른 select
이대로 더 효과에서 선택한 것과 selects
필터링하고, 쓴 작은 POC입니다.
아마도 그것은 당신에게 몇 가지 아이디어를 제공 할 수 있습니다 :
function selectFilter(_maps)
{
var map = {};
var i = _maps.length + 1; while (i -= 1)
{
map = _maps[i - 1];
(function (_selectOne, _selectTwo, _property)
{
var select = document.getElementById(_selectTwo);
var options = select.options;
var option = {};
var cache = [];
var output = [];
var i = options.length + 1; while (i -= 1)
{
option = options[i - 1];
cache.push({
text: option.text,
value: option.value,
property: option.getAttribute(_property)
});
}
document.getElementById(_selectOne).onchange = function()
{
var selectedProperty = this
.options[this.selectedIndex]
.getAttribute(_property);
var cacheEntry = {};
var cacheEntryProperty = undefined;
output = [];
var i = cache.length + 1; while (i -= 1)
{
cacheEntry = cache[i - 1];
cacheEntryProperty = cacheEntry.property;
if (cacheEntryProperty === selectedProperty)
{
output.push("<option value=" + cacheEntry.value + " "
_property + "=" + cacheEntryProperty + ">" +
cacheEntry.text + "</option>");
}
}
select.innerHTML = output.join();
};
}(map.selectOne, map.selectTwo, map.property));
}
}
$(function()
{
selectFilter([
{selectOne: "select1", selectTwo: "select2", property: "entityid"},
{selectOne: "select2", selectTwo: "select3", property: "value"}
]);
});
이 그런 요소를 꺼내해야 할 것 -이 누른 키를 포함하는 첫 번째 옵션을 선택합니다 동안) – roenving