我使用jQuery基於Cascade plugin可能它的工作,但我發現了很多的問題,它JQuery級聯下拉問題?
也許有人已經面臨着這個插件,也許能有所幫助。
所以,我用這個插件中的位置過濾
location http://clip2net.com/clip/m12007/1246819525-clip-2kb.png location http://clip2net.com/clip/m12007/1246819608-clip-3kb.png
這纔是我的CS代碼:
public JsonResult getChildren(string val)
{
if (val.IsNotNull())
{
int lId = val.ToInt();
Cookie.Location = val.ToInt();
var forJSON = from h in Location.SubLocationsLoaded(val.ToInt())
select new { When = val, Id = h.Id, Name = h.Name, LocationName = h.LocationType.Name };
return this.Json(forJSON.ToArray());
}
else
return null;
}
這纔是我的JS代碼:
<script type="text/javascript">
function commonMatch(selectedValue) {
$("#selectedLocation").val(selectedValue);
return this.When == selectedValue;
};
function commonTemplate(item) {
return "<option value='" + item.Id + "'>" + item.Name + "</option>";
};
$(document).ready(function() {
$("#chained_child").cascade("#Countries", {
ajax: {
url: '/locations/getChildren'
},
template: commonTemplate,
match: commonMatch
}).bind("loaded.cascade", function(e, target) {
$(this).prepend("<option value='empty' selected='true'>------[%Select] Län------</option>");
$(this).find("option:first")[0].selected = true;
});
$("#chained_sub_child").cascade("#chained_child", {
ajax: {
url: '/locations/getChildren'
},
template: commonTemplate,
match: commonMatch
}).bind("loaded.cascade", function(e, target) {
$(this).prepend("<option value='empty' selected='true'>------[%Select] Kommun------</option>");
$(this).find("option:first")[0].selected = true;
});
$("#chained_sub_sub_child").cascade("#chained_sub_child", {
ajax: {
url: '/locations/getChildren'
},
template: commonTemplate,
match: commonMatch
}).bind("loaded.cascade", function(e, target) {
$(this).prepend("<option value='empty' selected='true'>------[%Select] Stad------</option>");
$(this).find("option:first")[0].selected = true;
});
});
我添加一個條件,以jquery.cascade.ext.js
if (opt.getParentValue(parent) != "empty")
$.ajax(_ajax);
爲了防止Ajax請求沒有選擇的值,但我面臨的問題,當我在第一箱三維框復位選擇和波紋管不刷新: WTF? http://clip2net.com/clip/m12007/1246822534-clip-2kb.png
而第二個問題: 我想知道哪裏是注入我自己的功能,將做一些事情,有一個要求,最好的地方 - 我需要知道,所有箱子完成的工作。
如果有人在裏面工作,讓我知道也許我們可以一起找到解決方案。 感謝您的建議...
非常感謝你 – omoto 2009-07-07 14:06:54