jquery - 无法读取 null 的属性“createDocumentFragment”
问题描述
<div class="input-group col-md-6">
<select id="select-mesaj-gonderim-turleri" class="form-control mesajgonderimturusec input-circle" asp-
for="Model.FKMesajGonderimTurleriID" asp-items="ViewBag.MesajGonderimTurleri" required>
</select>
</div>
<div class="input-group col-md-6">
<select id="select-birimler" class="form-control birimsec input-circle" asp-for="Model.FkBirimID" asp-
items="ViewBag.Birimler" required></select>
</div>
<script>
function GetBirimGetir() {
var url = '@Url.Action("GetBirimlerByBirimKod", "Helper", new { area = "Yonetim" })';
console.log("url", url);
LoadSelectList(url, null, 'Seçiniz', 'select-birimler', null, false, ('@ViewBag.GuncellenecekBirimID' != null && '@ViewBag.GuncellenecekBirimID' > 0) ? '@ViewBag.GuncellenecekBirimID' : null, 'Birim Bulunamadı');
};
function GetMesajGonderimTurleriniGetir() {
var url = '@Url.Action("GetMesajGonderimTurleriByID", "Helper", new { area = "Yonetim" })';
console.log("url",url);
LoadSelectList(url, null, 'Seçiniz', 'select-mesaj-gonderim-turleri', null, false,('@ViewBag.GuncellenecekMesajGonderimTurleriID' !== null && '@ViewBag.GuncellenecekMesajGonderimTurleriID' > 0) ? '@ViewBag.GuncellenecekMesajGonderimTurleriID' : 'null', 'Tür Bulunamadı');
};
$(document).ready(function () {
$(document).load('change', '.birimsec', GetBirimGetir);
$(document).load('change', '.mesajgonderimturusec', GetMesajGonderimTurleriniGetir);
});
</script>
我正在使用 loadselectlist javascript 方法来填充下拉列表
当我进入插入页面时没有问题。下拉列表被填满。我可以选择并保存。进入更新页面时会抛出下图所示的错误
当我进入插入页面时没有问题。下拉列表被填满。我可以选择并保存。进入更新页面时会抛出下图所示的错误
function LoadSelectList(url, value, label, target, callback, selectAll, selecteds, actionEmptyLabel) {
debugger;
var targetDropDown = $('#' + target);
console.log("actionEmptyLabel",actionEmptyLabel);
$.getJSON(url, value, function (result) {
if (result.Action != GLOBAL_VARIABLES.ActionSuccess) {
Warning(result.Message);
return false;
}
var items = result.Data;
targetDropDown.empty();
targetDropDown.removeAttr('disabled');
if (items !== null && items.length > 0) {
if (label !== null && label !== undefined) {
targetDropDown.append($('<option/>', {
value: '',
text: label
}));
}
console.log(" $(this)", $(this));
console.log(" targetDropDown", targetDropDown);
$.each(items, function (index, item) {
console.log("index");
if (item.Disabled) {
targetDropDown.append($('<option/>', {
value: item.Value,
text: item.Text,
disabled: "disabled"
}));
} else {
targetDropDown.append($('<option/>', {
value: item.Value,
text: item.Text
}));
}
});
} else {
if (actionEmptyLabel !== null && actionEmptyLabel !== undefined) {
targetDropDown.append($('<option/>', {
value: '',
text: actionEmptyLabel
}));
}
}
if (selectAll) {
var selected = [];
targetDropDown.find("option").each(function (i, e) {
selected.push($(e).attr("value"));
});
targetDropDown.val(selected).trigger("change");
}
if (selecteds) {
targetDropDown.val(selecteds).trigger("change");
}
}).fail(function (xhr, status, error) {
console.error(xhr);
console.error(error);
});
}
解决方案
尝试将模式附加到当前文档时出现相同的错误消息
$.get(url).done(function (data) {
$(document).append(data).find('.modal').modal('show');
});
问题是不能附加到整页,而只能附加到正文
$.get(url).done(function (data) {
$(document.body).append(data).find('.modal').modal('show');
});
推荐阅读
- c# - Git忽略目录不适用于.vs目录
- django - 如何在共享或 VPS 主机上配置 Django 2.2.8 的设置
- java - Maven 多模块清理和构建失败
- selenium - 在 xpath selenium 中按确切文本搜索
- php - 使用 Laravel 6 和护照进行身份验证使用自定义字段和实体
- sql - 查询执行期间超出 Bigquery 资源 - 优化
- python - 其他人是否需要安装相同的模块才能在 Python 中运行我的代码?
- c++ - 在 C++ 中,重复声明仍然是一个问题吗?
- c# - 属性名称包含下划线的 JsonProperty 返回 null
- c# - 使用 .NET 和动态 EDM 模型的可编辑 OData 服务