如何将级联功能绑定到DOM中尚未包含的元素:
(function ($) {
$.fn.cascade = function (options) {
var defaults = {};
var opts = $.extend(defaults, options);
// REST OF THE CODE NOT IMPORTANT FOR THE QUESTION //
};
})(jQuery);
将加载的部分视图将包含:
@Html.DisplayNameFor(m => m.PTDistrict_Id)
@Html.DropDownListFor(m => m.PTDistrict_Id, Model.PTDistrictList, HeelpResources.PTDistrictViewDropDownListFirstRecord, new { id = "districtDropdown" })
@Html.ValidationMessageFor(m => m.PTDistrict_Id)
我试过这个但没有运气:
$(document).on("change", "#districtDropdown", function () {
$.cascade({
url: "/Address/ListCouncilByDistrict",
paramName: "districtId",
firstOption: 'Selecione o Concelho...',
childSelect: $("#councilDropdown")
});
});
有什么想法吗?感谢。
答案 0 :(得分:0)
喜欢那个
$(document).on("change", "#districtDropdown", function () {
$(this).cascade({
...
});
});
答案 1 :(得分:0)
答案 2 :(得分:0)
这样的事情可以适合你的情况:
<select>
<option class="event" data-action="Cascade" data-someParameter="fooBar">Foo</option>
</select>
<script>
var Event = {
Cascade: function(ele){
//enter your actual cascade function.
alert(ele.attr("data-someParameter")); //alerts "123"
};
};
$(".event").on("click",function(){
var ele = $(this);
Event[ele.attr("data-action")](ele);
});
</script>