我在父 View 中有一个 JavaScript 函数 Check()
,并且该父 View 有一个名为 child 的部分 View 。这个 subview 中有一个 java 脚本函数,该函数将在 anchor 标记单击后触发,然后调用我的父 View 的 Check()
函数。
所以我需要的是从这个部分 View 的函数中调用父 View 的 Check()
函数。 简单地将父 View 的脚本函数放入局部 View 中并不会调用Check()
。我该怎么做,请纠正我
这就是我到目前为止所做的,
我的部分 View 脚本函数看起来像
function supp_checkAndReset(elem) {
var currentSelected = $(elem).attr('id');
$('.supp_panelfilterresultholder span[title="' + currentSelected + '"]').remove();
$('.supp_panelfiltersuggestion input[value="' + currentSelected + '"]').prop('checked', false);
Check();
}
我的父 View 脚本函数位于脚本标记下,看起来像
function Check() {
var supp_fullCheckList = $("#supp_filterWithThis").val();
var practice_fullCheckList = $("#practice_filterWithThis").val();
var county_fullCheckList = $("#county_filterWithThis").val();
var state_fullCheckList = $("#state_filterWithThis").val();
var ratebase_sliderValue = $("#ratebase_sliderValue").val();
var clientRating_sliderValue = $("#clientRating_sliderValue").val();
var panelRating_sliderValue = $("#panelRating_sliderValue").val();
$.ajax({
url: '@Url.Action("GetSearchResultBasedOnFilters", "SearchResult")',
type: 'GET',
data: {
supp_fullCheckList: supp_fullCheckList, practice_fullCheckList: practice_fullCheckList, county_fullCheckList: county_fullCheckList,
state_fullCheckList: state_fullCheckList, ratebase_sliderValue: ratebase_sliderValue, clientRating_sliderValue: clientRating_sliderValue, panelRating_sliderValue: panelRating_sliderValue
},
success: function (response) {
var totRecordCount = $('#RecordTotalCount').val();
$('#TotRecordCount').html(totRecordCount);
$('#searchArea').html('');
$('#searchArea').html(response);
},
error: function (xhr, status, error) {
alert(status + " : " + error);
}});
}
最佳答案
我也遇到了同样的问题。将 javascript 函数 supp_checkAndReset(elem)
和 Check()
保留在主视图(即父 View )中。因此,它可以从 View 和部分 View 访问。
在父 View 中应该是这样的:
<script type="text/javascript">
function supp_checkAndReset(elem) {
var currentSelected = $(elem).attr('id');
$('.supp_panelfilterresultholder span[title="' + currentSelected + '"]').remove();
$('.supp_panelfiltersuggestion input[value="' + currentSelected + '"]').prop('checked', false);
Check();
}
function Check() {
var supp_fullCheckList = $("#supp_filterWithThis").val();
var practice_fullCheckList = $("#practice_filterWithThis").val();
var county_fullCheckList = $("#county_filterWithThis").val();
var state_fullCheckList = $("#state_filterWithThis").val();
var ratebase_sliderValue = $("#ratebase_sliderValue").val();
var clientRating_sliderValue = $("#clientRating_sliderValue").val();
var panelRating_sliderValue = $("#panelRating_sliderValue").val();
$.ajax({
url: '@Url.Action("GetSearchResultBasedOnFilters", "SearchResult")',
type: 'GET',
data: {
supp_fullCheckList: supp_fullCheckList, practice_fullCheckList: practice_fullCheckList, county_fullCheckList: county_fullCheckList,
state_fullCheckList: state_fullCheckList, ratebase_sliderValue: ratebase_sliderValue, clientRating_sliderValue: clientRating_sliderValue, panelRating_sliderValue: panelRating_sliderValue
},
success: function (response) {
var totRecordCount = $('#RecordTotalCount').val();
$('#TotRecordCount').html(totRecordCount);
$('#searchArea').html('');
$('#searchArea').html(response);
},
error: function (xhr, status, error) {
alert(status + " : " + error);
}});
}
关于javascript - 从部分 View 的 javascript 函数调用父 View 的 javascript 函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31018057/