我正在使用基于 JQuery 的级联插件 https://web.archive.org/web/20111206072619/http://plugins.jquery.com:80/project/cascade;可能它有效,但我发现它有很多问题。
也许有人已经遇到过这个插件,也许可以提供帮助。
所以,我使用这个插件进行位置过滤
http://clip2net.com/clip/m12007/1246819525-clip-2kb.png http://clip2net.com/clip/m12007/1246819525-clip-2kb.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);
To prevent Ajax request without selected value, but I faced with problem, when I reset selection in first box 3d box and below does not refresh:
第二期:
我想知道在哪里注入我自己的函数的最佳位置,该函数可以做一些事情,有一个要求 - 我需要知道所有盒子都完成了工作。