简体   繁体   English

JavaScript运行时错误:对象不支持jquery-ui.js中的属性或方法“替换”

[英]JavaScript runtime error: Object doesn't support property or method 'replace' in jquery-ui.js

I have below methods in my Controller 我的控制器中有以下方法

[HttpPost]
public ActionResult GetEventsForMonth(int month, int year)
{
    var events = new ListWithDuplicates();
    Dictionary<string, string> eventsnew = new Dictionary<string, string>();
    var ndates = (from nd in MCBDM.News where nd.nsdate.Month==month && nd.nsdate.Year==year select nd.nsdate).ToList();
    var nevents = (from ne in MCBDM.News where ne.nsdate.Month==month && ne.nsdate.Year==year select ne.nbrief).ToList();
    for (int i = 0; i < ndates.Count;i++ )
    {
        events.Add(ndates[i].Day.ToString(), nevents[i].ToString());
        eventsnew.Add(ndates[i].Day.ToString(), nevents[i].ToString());
    }

    Thread.Sleep(1000);
    return Json(events);
  }

public class ListWithDuplicates : List<KeyValuePair<string, string>>
{
    public void Add(string key, string value)
    {
        var element = new KeyValuePair<string, string>(key, value);
        this.Add(element);
    }
}

I have below code in my _calendar.cshtml file 我的_calendar.cshtml文件中有以下代码

<div id="datepicker">

</div>

<div class="row modal-line pad-left20 error-text" id="cal_error">

</div>

<script type="text/javascript">

    $(function () {
        $("#datepicker").datepicker({
            beforeShowDay: function (date) {
                var day = date.getDate();
                if (day in calendarEvents) {
                    if (calendarEvents[day] == undefined) {

                        return [true, 'isActive'];
                    }
                    return [true, 'isActive', calendarEvents[day]];
                }
                return [false, ''];
            },
            onChangeMonthYear: function (year, month, inst) {
                getEvents(month, year);
            }
        });
        var calendarDate = $("#datepicker").datepicker("getDate");
        getEvents(calendarDate.getMonth() + 1, calendarDate.getFullYear());
    });


</script>

and this in a separate js file 这在一个单独的js文件中

var calendarEvents = {};
function getEvents(month,year)
{
    $.ajax({
        url: "Home/GetEventsForMonth",
        type:"Post",
        data: JSON.stringify({ month: month, year: year }),
        dataType: 'json',
        processdata: false,
        contentType: 'application/json; charset=utf-8',
        success: function (data) { 
            calendarEvents = data; },
        error: function (xhr, ajaxOptions, thrownError) { 
            $("#cal_error").text("Something Went wrong!! Please try after sometime!!");
        },
        complete: function (x, y) { 
            $("#datepicker").datepicker("refresh"); }

    });
}

The problem I am facing is - whenever I pass events, which is of type ListWithDuplicates , I will get javascript error saying JavaScript runtime error: Object doesn't support property or method 'replace' in jquery-ui.js but if I Pass eventsnew through JSON method from controller, I won't get any error and calendar will be displayed properly. 我面临的问题是-每当我传递类型为ListWithDuplicates事件时,我都会收到javascript错误,提示JavaScript runtime error: Object doesn't support property or method 'replace' in jquery-ui.js但是如果我传递eventsnew通过控制器的JSON方法,我不会收到任何错误,并且日历将正确显示。 Can anyone please tell what's wrong with the type I use. 谁能告诉我我使用的类型有什么问题。 I have attached a screenshot of watch which has both events and eventsnew contents and both will have same type of format and contents. 我已经附上了手表的屏幕截图,其中既包含事件又包含事件新内容,并且都具有相同类型的格式和内容。 But still javascript error shows up when events is returned.! 但是当事件返回时仍然显示javascript错误。 屏幕截图

I just added below code to my ajax success method and that worked like a charm.. :) 我只是将以下代码添加到了我的ajax成功方法中,它的工作就像一个魅力.. :)

The problem was eventsnew was returning an object and events was returning array of object as result. 问题是eventsnew返回一个对象,而events返回作为结果的对象数组。 I just started retrieving array of objects and stored it as object.. 我刚刚开始检索对象数组并将其存储为对象。

  success: function (data) {
            $.each(data, function (index) {
                var obj = data[index];
                calendarEvents[obj.Key] = obj.Value;
            });
    },

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 JavaScript运行时错误:对象不支持属性或方法&#39;sooperfish&#39; - JavaScript runtime error: Object doesn't support property or method 'sooperfish' javaScript 运行时错误:对象不支持属性或方法“openDatabase” - javaScript runtime error: Object doesn't support property or method 'openDatabase' JavaScript运行时错误:对象不支持属性或方法'contains' - JavaScript runtime error: Object doesn't support property or method 'contains' javascript运行时错误对象不支持属性或方法&#39;tabs&#39; - javascript runtime error object doesn't support property or method 'tabs' JavaScript 运行时错误:对象不支持属性或方法“addEventListener” - JavaScript runtime error: Object doesn't support property or method 'addEventListener -JavaScript运行时错误:对象不支持属性或方法“ datetimepicker” - - JavaScript runtime error: Object doesn't support property or method 'datetimepicker' JavaScript运行时错误:对象不支持属性或方法&#39;jqGrid&#39; - JavaScript runtime error: Object doesn't support property or method 'jqGrid' JavaScript运行时错误:对象不支持属性或方法“自动完成” - JavaScript runtime error: Object doesn't support property or method 'autocomplete' JavaScript运行时错误:对象不支持属性或方法“ prop” - JavaScript runtime error: Object doesn't support property or method 'prop' JavaScript运行时错误:对象不支持属性或方法&#39;applyFilterAsync&#39; - JavaScript runtime error: Object doesn't support property or method 'applyFilterAsync'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM