gpt4 book ai didi

javascript - 为什么会出现 Uncaught TypeError : Cannot read property 'dataSource' of undefined

转载 作者:行者123 更新时间:2023-11-28 03:19:37 28 4
gpt4 key购买 nike

我放弃了这个可怕的错误,我无法继续前进当我想单击网格行时,我想打开弹出窗口并尝试显示该行的详细信息。我正在使用 LoadContentFrom 函数显示详细信息,但是当我尝试双击 row 时。我收到此错误 Orpac.js:16197 Uncaught TypeError: Cannot read property 'dataSource' of undefined

这是我的主视图

<script type="text/javascript">
$(document).ready(function () {
currentPageName = "LoyaltyCards";

});
</script>
@{
var columnList = ViewBag.List;

int[] series = new int[3];
series[0] = 50;
series[1] = 100;
series[2] = 200;
}
<script src="../../Scripts/kendo/2018.1.117/kendo.all.min.js" type="text/javascript"></script>
<script src="../../Scripts/kendo/2018.1.117/kendo.aspnetmvc.min.js" type="text/javascript"></script>

<div id="Over" class="k-overlay" style="opacity: 0.5; z-index: 10000; display: none;"></div>
<header><h3><span id="lylheader">@ViewData["LoyaltyCards"]</span></h3></header>

<div class="k-rtl">
@( Html.Kendo().Grid<Orpac.Models.DATA>()
.Name("grdLoyaltyCards")
.DataSource(ds => ds
.Ajax()
.Read(r => r.Action("GridLoyaltyCardsBinding", "Loyalty").Type(HttpVerbs.Get)).PageSize(20)
)
.Columns(columns =>
{

columns.Bound(e => e.McrKod).Width(90).ClientTemplate("<input type='checkbox' value='#=McrKod#'/>").Title((string)ViewData["Select"]).Filterable(false);
columns.Bound(e => e.McrKod).Width(200).Title((string)ViewData["CardNo"]).Encoded(false);
columns.Bound(e => e.CrdKod).Width(150).Title((string)ViewData["CardType"]);
columns.Bound(e => e.McrStatus).Width(150).Title((string)ViewData["Status"]);
columns.Bound(e => e.McrIsim).Width(150).Title((string)ViewData["Name"]);
columns.Bound(e => e.McrSoyad).Width(150).Title((string)ViewData["Surname"]);
columns.Bound(e => e.McrMail).Width(150).Title((string)ViewData["EMail"]);
columns.Bound(e => e.McrGsm).Width(150).Title((string)ViewData["Phone"]);
columns.Bound(e => e.McrBasla).Width(200).Title((string)ViewData["StartDate"]).ClientTemplate("#= kendo.toString(McrBasla, 'dd.MM.yyyy HH:mm:ss') #");
columns.Bound(e => e.McrBitis).Width(200).Title((string)ViewData["EndDate"]);
columns.Bound(e => e.LstCode).Width(150).Title((string)ViewData["CustomerList"]);
columns.Bound(e => e.MegCode).Width(150).Title((string)ViewData["PointGroup"]);
columns.Bound(e => e.McrKimlikNo).Width(150).Title((string)ViewData["ID"]).Visible(false);

})
.Events(events => events.DataBound("onRowDataBoundLoyalty").Change("ongrdLoyaltyRowSelect"))
.ToolBar(toolBar =>
{
toolBar.Excel().HtmlAttributes(new { @class = "btnexcel" }).Text(" ").IconClass("k-i-excel");
toolBar.Custom().Text((string)ViewData["SaveSettings"]).HtmlAttributes(new { @class = "k-button", id = "savegrid", href = "#", onclick = "SaveColumnPosition()" });
toolBar.Custom().Text((string)ViewData["ClearFilter"]).HtmlAttributes(new { @class = "k-button", id = "cleargrid", href = "#", onclick = "clearFiltersLoyalty()" });
}
)
.Excel(excel => excel.FileName((string)ViewData["LoyaltyCards"] + ".xlsx").AllPages(false).Filterable(true))
.Selectable()
.Scrollable(scrolling => scrolling.Height("100%"))
.Sortable()
.Pageable(pageable => pageable
.Refresh(true)
.PageSizes(series)
.ButtonCount(10))
.Filterable(filterable => filterable
.Extra(false)
.Operators(operators => operators
.ForString(str => str.Clear()
.StartsWith("Starts with")
.Contains("Contains")
))
)
.Groupable()
.Resizable(config =>
{
config.Columns(true);
})
.Reorderable(config =>
{
config.Columns(true);
})
.ColumnMenu()
)

</div>
<div class="k-rtl">
@{ Html.Kendo().Window()
.Name("LoyaltyWindow")
.Title((string)ViewData["LoyaltyCards"])
.Actions(b => b.Close())
.LoadContentFrom("ContentOfLoyalty", "Loyalty") ////I WANT TO OPEN DETAIL FROM HERE
.Modal(true)
.Visible(false)
.Draggable(true)
.Resizable()
.Width(1300)
.Height(600)
.Render();
}
</div>

<script>
$(function () {
load();

$('.k-grid-content', this).on('click', function (e) {
var CategoryVisibility = "@ViewData["CategoryInLoyalty"].ToString()";
openloyaltywindow(CategoryVisibility); ////HERE MY DOUBLE CLICK FUNCTION...


$('#grdLoyaltyCards').on('change', ':checkbox', function (e) {
var $check = $(this);
if ($check.is(':checked')) {
selectedLoyaltyCards.push($check.val());
}
else {
selectedLoyaltyCards = $.grep(selectedLoyaltyCards, function (item, index) {
return item != $check.val();
});
}

});

$("#grdLoyaltyCards").kendoTooltip({
filter: "td",
position: "right",
content: "@ViewData["Tooltip"].ToString()"
}).data("kendoTooltip");
})

function SaveColumnPosition() {
var grid = $("#grdLoyaltyCards").data("kendoGrid");
localStorage["kendo-grid-options-loyaltycard"] = kendo.stringify(grid.getOptions());
}

function load() {
var grid = $('#grdLoyaltyCards').data("kendoGrid");
var toolBar = $("#grdLoyaltyCards .k-grid-toolbar").html();

var options = localStorage["kendo-grid-options-loyaltycard"];
if (options) {
grid.setOptions(JSON.parse(options));
$("#grdLoyaltyCards .k-grid-toolbar").html(toolBar);
$("#grdLoyaltyCards .k-grid-toolbar").addClass("k-grid-top");
}
}

这是我的详细 View

@{
var columnList = ViewBag.List;

int[] pageseries = new int[3];
pageseries[0] = 50;
pageseries[1] = 100;
pageseries[2] = 200;
}
@{Html.Kendo().TabStrip().Name("LoyaltyTab").Animation(enable => enable.Open(effects => effects.Expand(ExpandDirection.Vertical)))
.Events(events => events.Select("selectLoyaltyTab"))
.Items(item1 =>
{
item1.Add().Text((string)ViewData["Overview"]).HtmlAttributes(new { id = "first" }).Selected(true).Visible((bool)ViewData["ShowOverview"]).Content(@<text>


<h3><b>@ViewData["Overview"] <span id="daylabel"></span></b></h3>
<div>
Select Year : @(Html.Kendo().ComboBox().AutoBind(false)
.Name("cmbyear")
.DataValueField("YearId")
.DataTextField("YearText")
.DataSource(binding => binding.Read(read =>
{
read.Action("CmbBindYear", "Loyalty");
}))
.Value(ViewData["YearNow"].ToString())
.Events(e => e.Change("changeloyaltyyear"))
)
</div>

<h3><b> @ViewData["CustomerInformation"]</b></h3>
<div style=" float:left;">
<br />
<h3><b>@ViewData["Questionare"]</b></h3>
@*<div id="grdQuestionar"></div>*@
@( Html.Kendo().Grid<DATA>()
.Name("grdLoyalty")
.DataSource(ds => ds
.Ajax()
.Read(r => r.Action("GridLoyaltyBinding", "Loyalty"))
)
.Columns(columns =>
{
columns.Bound(e => e.Question).Title("Question");
columns.Bound(e => e.Answer).Title("Answer");
})
.AutoBind(false)
.HtmlAttributes(new { style = "width: 300px; height:100%;" })
.Selectable()
.Sortable()
)

</div>
<div style="float:left;margin-left: 50px;margin-top: -50px;">
@{Html.Kendo().Chart<Orpac.Models.Mg_Web_LoyaltyTrxCount_Result>()
.Name("loyaltytrxlist").Title((string)ViewData["TranChart"])
.Legend(legend => legend
.Visible(true).Position(Kendo.Mvc.UI.ChartLegendPosition.Bottom)
.Labels(labels =>
{
labels.Template("#= text #");
}
)
).HtmlAttributes(new { style = "width: 500px; height:300px;" })
.ChartArea(configurator => configurator.Background("transparent"))
.DataSource(ds =>
{
ds.Read(read => read.Action("LoyaltyTransactionsPerYear", "Loyalty", new { year = DateTime.Now.Year }));
}).AutoBind(false)
.Series(series =>
{
series.Line(data => data.Number_Of_Transactions);
series.Line(data => data.Sum_of_Quantity);
})
.CategoryAxis(axis => axis
.Categories(data1 => data1.Monthstr)
)
.Theme((string)ViewData["themes"])
.ValueAxis(axis => axis
.Numeric().Labels(labels => labels.Format("{0}"))
)
.Tooltip(tooltip => tooltip
.Visible(true)
.Format("{0}")
).Render();
}
</div>


<div style="clear: both;"></div>

</text>);

item1.Add().Text((string)ViewData["Transactions"]).HtmlAttributes(new { id = "third" }).Visible((bool)ViewData["ShowTran"]).Content(@<text>
@( Html.Kendo().Grid<Orpac.Models.Mg_Web_LylHarGet_Result>()
.Name("grdLoyaltyTransaction")
.DataSource(ds => ds
.Ajax()
.Read(r => r.Action("GridLoyaltyTransactionBinding", "Loyalty").Type(HttpVerbs.Get)).PageSize(20).Aggregates(agg =>
{
agg.Add(a => a.MshTutar).Sum();
agg.Add(a => a.MshMiktar).Sum();
agg.Add(a => a.MshIskonto).Sum();
agg.Add(a => a.PuanBakiye).Sum();
})
)
.ToolBar(toolBar =>
{
toolBar.Custom().Text(" ").Url(Url.Action("ExportCsvTranLoyalty", "Loyalty", new { page = 1, pageSize = "~", filter = "~", sort = "~" })).HtmlAttributes(new { @class = "btnexcel" });
toolBar.Custom().Text("Clear Filter").HtmlAttributes(new { @class = "k-button", id = "cleargrid", href = "#", onclick = "clearFiltersTranLoyalty()" });
}
)
.Columns(columns =>
{
columns.Bound(e => e.MshIdent).Visible(false);
columns.Bound(e => e.MshTxnTim).Title("Transaction " + (string)ViewData["Date"]).ClientTemplate("#= kendo.toString(MshTxnTim, 'dd.MM.yyyy HH:mm') #").ClientGroupHeaderTemplate("Transaction Date: #= kendo.toString(value, 'dd.MM.yyyy HH:mm') #");
columns.Bound(e => e.MshMagazaNam).Title((string)ViewData["Station"]);
columns.Bound(e => e.MshStok).Title((string)ViewData["StockNam"]);
columns.Bound(e => e.MshTutar).Title((string)ViewData["Amount"]).ClientTemplate("#= FormatMoney(MshTutar) #").Encoded(true);
columns.Bound(e => e.MshMiktar).Title((string)ViewData["Quantity"]);
columns.Bound(e => e.MshTipName).Title((string)ViewData["Transaction"] + (string)ViewData["Tip"]);
columns.Bound(e => e.iskontotipiName).Title((string)ViewData["Discount"] + (string)ViewData["Tip"]);
columns.Bound(e => e.MshIskonto).Title((string)ViewData["Discount"]).ClientTemplate("#= FormatMoney(MshIskonto) #").Encoded(true);
columns.Bound(e => e.PuanBakiye).Title((string)ViewData["Point"]);
columns.Bound(e => e.MshCmpKod).Title((string)ViewData["Campaign"] + (string)ViewData["Tip"]);
columns.Bound(e => e.MshIdent).Title((string)ViewData["TransactionId"]);
columns.Bound(e => e.MshTarih).Title((string)ViewData["Account"] + (string)ViewData["Date"]).ClientTemplate("#= kendo.toString(MshTarih, 'dd.MM.yyyy') #").ClientGroupHeaderTemplate("Account Date: #= kendo.toString(value, 'dd.MM.yyyy') #");

})
.AutoBind(false)
.Selectable()
.Scrollable(scroll => scroll.Height(600))
.Sortable()
.Pageable(pageable => pageable
.Refresh(true)
.PageSizes(pageseries)
.ButtonCount(10))
.Filterable(filterable => filterable
.Extra(false)
.Operators(operators => operators
.ForString(str => str.Clear()
.StartsWith("Starts with")
.Contains("Contains")
))
)
.Groupable()
.Resizable(config =>
{
config.Columns(true);
})
.Reorderable(config =>
{
config.Columns(true);
})
.ColumnMenu()
)
</text>);

}).Render();
}

这是我的 _Layout.cshtml 头部

<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="author" content="Şaul Yaşar CEMAL" />
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
<script src="~/Scripts/kendo/2018.1.117/jquery.min.js"></script>
<script src="~/Scripts/kendo/2018.1.117/jszip.min.js"></script>
<script src="~/Scripts/kendo/2018.1.117/kendo.all.min.js" type="text/javascript"></script>
<script src="~/Scripts/kendo/2018.1.117/kendo.aspnetmvc.min.js" type="text/javascript"></script>


<script src="~/Scripts/bootstrap.min.js"></script>
<script src="~/bower_components/metisMenu/src/metisMenu.js"></script>
<script src="~/Scripts/sb-admin-2.js"></script>
<script src="../../js/Orpac.js" type="text/javascript"></script>
<script src="../../js/accounting.min.js" type="text/javascript"></script>
<script src="../../js/numeral.js"></script>
<script src="../../js/jquery-ui-1.10.4.js" type="text/javascript"></script>
<script src="~/js/jquery.maskedinput.js"></script>
<script src="~/js/jquery.equalHeight.js"></script>
<script src="~/js/jquery.tablesorter.min.js"></script>
<script src="~/Scripts/kendo.modernizr.custom.js"></script>
</head>

这是我的 js 文件

function openloyaltywindow(CategoryVisibility) {
var vCategory = CategoryVisibility;
$("#pointval").hide();
$("#discountval").hide();
$("#redemptionval").hide();

var grid = $('#grdLoyaltyCards').data("kendoGrid");
var dataItem = grid.dataItem(grid.select());

$("#daylabel").text("1/1/" + (new Date()).getFullYear() + " - " + (new Date).getDay() + "/" + ((new Date).getMonth() + 1) + "/" + (new Date()).getFullYear());

$("#yearid").text((new Date()).getFullYear());

var thisyear = (new Date()).getFullYear();

var combo = $("#cmbyear").data('kendoComboBox');
combo.dataSource.read(); // I'M GETTING ERROR FROM HERE ALL KENDO WIDGETS ARE UNDEFINED...

$("#lpname").html(dataItem.McrIsim);
$("#lpsname").html(dataItem.McrSoyad);
$("#lpcardtype").html(dataItem.CrdKod);
$("#lpcardnumber").html(dataItem.McrKod);
$("#lpcardstatus").html(dataItem.McrStatus);
$("#lpcstlist").html(dataItem.LstCode);
$("#lpgroup").html(dataItem.MegCode);

$("#lyltxtname").val(dataItem.McrIsim);
$("#lyltxtsname").val(dataItem.McrSoyad);
$("#lyltxtemail").val(dataItem.McrMail);
$("#lyltxtphone").val(dataItem.McrGsm);
$("#lyltxtid").val(dataItem.McrKimlikNo);


var todayDate = dataItem.McrBasla;
var date = todayDate.getDate();
var month = todayDate.getMonth() + 1;
var year = todayDate.getFullYear();

var invdate = date + "/" + month + "/" + year + " ";

$("#lpstartdate").html(invdate);
$("#lpenddate").html(dataItem.McrBitis);

$("#LoyaltyTab").data("kendoTabStrip").select(0);
$('#LoyaltyWindow').data('kendoWindow').maximize().open();
$("#LoyaltyWindow").closest(".k-window").css({
top: 0,
left: 0
});


var chart = $("#loyaltytrxlist").data('kendoChart');
chart.dataSource.read();
chart.refresh();

if (vCategory == "Yes") {
var chartpie = $("#loyaltypie").data('kendoChart');
chartpie.dataSource.read();
chartpie.refresh();
}


var grid = $("#grdLoyalty").data('kendoGrid');
grid.dataSource.read();

$.ajax({
url: '../Loyalty/GetPointsForCard',
data: { card: dataItem.McrKod, pyear: thisyear },
success: function (data) {
if (data != null) {

//do something


}
else {

}
}
});
}

最佳答案

您需要等待小部件初始化,尝试将代码放入其中:

$(window).load(function () { //your js code}

关于javascript - 为什么会出现 Uncaught TypeError : Cannot read property 'dataSource' of undefined,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59285101/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com