【发布时间】:2016-10-04 19:39:54
【问题描述】:
我有一个下拉列表 (telerik dropdownlist),对于每个选项,我都会从我的控制器调用不同的局部视图。
onChange = function (e)
{
var product = e.value;
if (product)
{
$.post( myUrl,
{ CodigoProduto : product }, // passing the product to my controller
function (retorno) {
// insert the partial view in a div
$('#AreaGenerica').html(retorno);
}
);
}
}
第一个选项返回包含 javascript 代码的局部视图
<script type=\"text/javascript\">
function PartialViewFunction () {
alert("test");
}
</script>
<h2>Option A</h2>
第二个选项返回不带任何 javascript 代码的局部视图。
在我看来,我在局部视图中调用函数
ViewFunction = function () {
// check if the function 'PartialViewFunction' exists.
if (typeof PartialViewFunction === "function")
{
PartialViewFunction();
}
};
我的问题是,如果我选择第一个选项,然后选择第二个,'PartialViewFunction' 仍然被调用,但它不应该因为它不存在于第二个局部视图中。
我试图在answer 之后删除包含我的部分视图的 div,但它没有用。
提前谢谢,我希望你能理解我的英语。
编辑:
@(Html.Telerik().DropDownList()
.Name("grpAutorizacaoPublicacao")
.SelectedIndex(0)
.Effects(e => e.Opacity())
.ClientEvents(e =>
{
e.OnChange("onChange");
})
.DataBinding(db => db.Ajax().Select("_ListaGrupoAutorizacao", "Publicador")))
【问题讨论】:
-
我知道我对通过 AJAX 检索的对话框内容做了很多相同的事情。我认为您在比较中只需要两个“=”符号。 if (typeof initDlg == 'function') initDlg();