通过KendoUI(Javascript/Jquery)将日期传递给WCF REST服务
想法 我有日历控件,可以从中选择不同的日期。根据选择的日期,我对WCF服务(GetDealData())进行ajax调用,以获取一些数据集。 你能告诉我这里出了什么问题吗?两天来,我一直在想为什么每次我执行OnDateChange方法时,即使我在日历控件上选择了不同的日期,我的GetRemoteData()方法都会传递相同的日期(2012年10月25日)。这是否与json数据分配不正确有关通过KendoUI(Javascript/Jquery)将日期传递给WCF REST服务,javascript,wcf,rest,jquery,kendo-grid,Javascript,Wcf,Rest,Jquery,Kendo Grid,想法 我有日历控件,可以从中选择不同的日期。根据选择的日期,我对WCF服务(GetDealData())进行ajax调用,以获取一些数据集。 你能告诉我这里出了什么问题吗?两天来,我一直在想为什么每次我执行OnDateChange方法时,即使我在日历控件上选择了不同的日期,我的GetRemoteData()方法都会传递相同的日期(2012年10月25日)。这是否与json数据分配不正确有关 $('#calendarContainer').kendoCalendar({ forma
$('#calendarContainer').kendoCalendar({
format: "dd/MM/yyyy",
culture: "en-GB",
change: onDateChange
});
function onDateChange() {
var date = kendo.toString(this.value(), 'dd/MM/yyyy');
var bob = GetRemoteData(date);
$("#grid").data("kendoGrid").dataSource.data(bob);
$("#grid").data("kendoGrid").dataSource.read();
}
var chosenDate;
if (typeof date=="undefined")
{
alert("it is null " + date);
chosenDate = "25-10-2012";
}
else {
alert("it is not null " + date);
chosenDate = date;
}
source = new kendo.data.DataSource({
// autoSync:true,
transport: {
read: {
type: "GET",
url: "http://localhost:35798/RestServiceImpl.svc/GetDealData",
dataType: "jsonp",
contentType: "application/json; charset=utf-8",
cache: false,
data: {
startDate:chosenDate
}
}
},
schema: {
model: {
fields: {
DealNumber: { type: "string" },
DealIssuer: { type: "string" },
Ticker: { type: "string" },
DealType: { type: "string" },
DealValue: { type: "number" },
DealStatus: { type: "string" },
DealPricingCompletionDate: { type: "date" }
}
}
},
pageSize: 16
});
return source;
}
WCF Methods
[OperationContract]
[WebInvoke(Method = "GET", ResponseFormat = WebMessageFormat.Json,
BodyStyle = WebMessageBodyStyle.WrappedRequest,
UriTemplate = "GetDealData?startDate={startDate}")]
List<DealData> GetDealData(string startDate);
public List<DealData> GetDealData(string startDate)
{
CultureInfo culture = new CultureInfo("en-GB");
List<DealData> model = Service.GetDealData(Convert.ToDateTime(startDate,culture));
return model;
}
函数GetRemoteData(日期){
var chosenDate;
if (typeof date=="undefined")
{
alert("it is null " + date);
chosenDate = "25-10-2012";
}
else {
alert("it is not null " + date);
chosenDate = date;
}
source = new kendo.data.DataSource({
// autoSync:true,
transport: {
read: {
type: "GET",
url: "http://localhost:35798/RestServiceImpl.svc/GetDealData",
dataType: "jsonp",
contentType: "application/json; charset=utf-8",
cache: false,
data: {
startDate:chosenDate
}
}
},
schema: {
model: {
fields: {
DealNumber: { type: "string" },
DealIssuer: { type: "string" },
Ticker: { type: "string" },
DealType: { type: "string" },
DealValue: { type: "number" },
DealStatus: { type: "string" },
DealPricingCompletionDate: { type: "date" }
}
}
},
pageSize: 16
});
return source;
}
WCF Methods
[OperationContract]
[WebInvoke(Method = "GET", ResponseFormat = WebMessageFormat.Json,
BodyStyle = WebMessageBodyStyle.WrappedRequest,
UriTemplate = "GetDealData?startDate={startDate}")]
List<DealData> GetDealData(string startDate);
public List<DealData> GetDealData(string startDate)
{
CultureInfo culture = new CultureInfo("en-GB");
List<DealData> model = Service.GetDealData(Convert.ToDateTime(startDate,culture));
return model;
}
var chosenDate;
如果(日期类型==“未定义”)
{
警报(“为空”+日期);
chosenDate=“25-10-2012”;
}
否则{
警报(“不为空”+日期);
chosenDate=日期;
}
source=新的kendo.data.DataSource({
//自动同步:对,
运输:{
阅读:{
键入:“获取”,
url:“http://localhost:35798/RestServiceImpl.svc/GetDealData",
数据类型:“jsonp”,
contentType:“应用程序/json;字符集=utf-8”,
cache:false,
数据:{
起始日期:chosenDate
}
}
},
模式:{
型号:{
字段:{
DealNumber:{type:“string”},
DealIssuer:{type:“string”},
股票代码:{type:“string”},
DealType:{type:“string”},
DealValue:{type:“number”},
DealStatus:{type:“string”},
DealPricingCompletionDate:{type:“date”}
}
}
},
页面大小:16
});
返回源;
}
WCF方法
[经营合同]
[WebInvoke(Method=“GET”,ResponseFormat=WebMessageFormat.Json,
BodyStyle=WebMessageBodyStyle.WrappedRequest,
UriTemplate=“GetDealData?startDate={startDate}”)]
列出GetDealData(字符串startDate);
公共列表GetDealData(字符串startDate)
{
CultureInfo culture=新的CultureInfo(“en GB”);
列表模型=Service.GetDealData(Convert.ToDateTime(startDate,culture));
收益模型;
}
从您的代码来看,这个问题似乎与wcf无关——它只是一个JavaScript问题。
看来,你的约会总是没有定义
var chosenDate;
if (typeof date=="undefined")
{
alert("it is null " + date);
chosenDate = "25-10-2012";
}
else {
alert("it is not null " + date);
chosenDate = date;
}
source = new kendo.data.DataSource({
// autoSync:true,
transport: {
read: {
type: "GET",
url: "http://localhost:35798/RestServiceImpl.svc/GetDealData",
dataType: "jsonp",
contentType: "application/json; charset=utf-8",
cache: false,
data: {
startDate:chosenDate
}
}
},
schema: {
model: {
fields: {
DealNumber: { type: "string" },
DealIssuer: { type: "string" },
Ticker: { type: "string" },
DealType: { type: "string" },
DealValue: { type: "number" },
DealStatus: { type: "string" },
DealPricingCompletionDate: { type: "date" }
}
}
},
pageSize: 16
});
return source;
}
WCF Methods
[OperationContract]
[WebInvoke(Method = "GET", ResponseFormat = WebMessageFormat.Json,
BodyStyle = WebMessageBodyStyle.WrappedRequest,
UriTemplate = "GetDealData?startDate={startDate}")]
List<DealData> GetDealData(string startDate);
public List<DealData> GetDealData(string startDate)
{
CultureInfo culture = new CultureInfo("en-GB");
List<DealData> model = Service.GetDealData(Convert.ToDateTime(startDate,culture));
return model;
}
我会尝试找出this.value()
的值是多少,然后是-kendo.toString(this.value(),'dd/MM/yyyy')
value
var chosenDate;
if (typeof date=="undefined")
{
alert("it is null " + date);
chosenDate = "25-10-2012";
}
else {
alert("it is not null " + date);
chosenDate = date;
}
source = new kendo.data.DataSource({
// autoSync:true,
transport: {
read: {
type: "GET",
url: "http://localhost:35798/RestServiceImpl.svc/GetDealData",
dataType: "jsonp",
contentType: "application/json; charset=utf-8",
cache: false,
data: {
startDate:chosenDate
}
}
},
schema: {
model: {
fields: {
DealNumber: { type: "string" },
DealIssuer: { type: "string" },
Ticker: { type: "string" },
DealType: { type: "string" },
DealValue: { type: "number" },
DealStatus: { type: "string" },
DealPricingCompletionDate: { type: "date" }
}
}
},
pageSize: 16
});
return source;
}
WCF Methods
[OperationContract]
[WebInvoke(Method = "GET", ResponseFormat = WebMessageFormat.Json,
BodyStyle = WebMessageBodyStyle.WrappedRequest,
UriTemplate = "GetDealData?startDate={startDate}")]
List<DealData> GetDealData(string startDate);
public List<DealData> GetDealData(string startDate)
{
CultureInfo culture = new CultureInfo("en-GB");
List<DealData> model = Service.GetDealData(Convert.ToDateTime(startDate,culture));
return model;
}
对我来说,这听起来像是一些格式问题
var chosenDate;
if (typeof date=="undefined")
{
alert("it is null " + date);
chosenDate = "25-10-2012";
}
else {
alert("it is not null " + date);
chosenDate = date;
}
source = new kendo.data.DataSource({
// autoSync:true,
transport: {
read: {
type: "GET",
url: "http://localhost:35798/RestServiceImpl.svc/GetDealData",
dataType: "jsonp",
contentType: "application/json; charset=utf-8",
cache: false,
data: {
startDate:chosenDate
}
}
},
schema: {
model: {
fields: {
DealNumber: { type: "string" },
DealIssuer: { type: "string" },
Ticker: { type: "string" },
DealType: { type: "string" },
DealValue: { type: "number" },
DealStatus: { type: "string" },
DealPricingCompletionDate: { type: "date" }
}
}
},
pageSize: 16
});
return source;
}
WCF Methods
[OperationContract]
[WebInvoke(Method = "GET", ResponseFormat = WebMessageFormat.Json,
BodyStyle = WebMessageBodyStyle.WrappedRequest,
UriTemplate = "GetDealData?startDate={startDate}")]
List<DealData> GetDealData(string startDate);
public List<DealData> GetDealData(string startDate)
{
CultureInfo culture = new CultureInfo("en-GB");
List<DealData> model = Service.GetDealData(Convert.ToDateTime(startDate,culture));
return model;
}
您可以使用浏览器控制台调试JavaScriptHi evgenyl!谢谢你的回复。是,this.value()显示我在日历控件中选择的确切值。这是从alert语句中确认的,以查看实际值是什么。问题在于我在传输部分指定了数据属性。出于某种原因,它总是指定“25-10-2012”作为发送给WCF Rest服务的值,即使date变量有其他值。您调试了它吗?在if(typeof date==…)之后,chosenDate的值是多少?另外,我会尝试更改字符串date repsresentation by date(),是的,在if(typeof date==…)之后调试它时,我会选择实际值。。。这意味着变量“chosenDate”自动获取从“date”变量传入的所选值。只是当我调用read方法时,它传递null。我无法将其更改为Date对象,因为WCF服务器需要带有字符串参数的日期。目前我正在尽力将其作为字符串日期发送。也可能是我检查日期值的方式,或者我将值分配给ChoSenDate的方式尝试将“null”值修改为类似date的值。now()-这将为两个请求提供两个不同的日期
var chosenDate;
if (typeof date=="undefined")
{
alert("it is null " + date);
chosenDate = "25-10-2012";
}
else {
alert("it is not null " + date);
chosenDate = date;
}
source = new kendo.data.DataSource({
// autoSync:true,
transport: {
read: {
type: "GET",
url: "http://localhost:35798/RestServiceImpl.svc/GetDealData",
dataType: "jsonp",
contentType: "application/json; charset=utf-8",
cache: false,
data: {
startDate:chosenDate
}
}
},
schema: {
model: {
fields: {
DealNumber: { type: "string" },
DealIssuer: { type: "string" },
Ticker: { type: "string" },
DealType: { type: "string" },
DealValue: { type: "number" },
DealStatus: { type: "string" },
DealPricingCompletionDate: { type: "date" }
}
}
},
pageSize: 16
});
return source;
}
WCF Methods
[OperationContract]
[WebInvoke(Method = "GET", ResponseFormat = WebMessageFormat.Json,
BodyStyle = WebMessageBodyStyle.WrappedRequest,
UriTemplate = "GetDealData?startDate={startDate}")]
List<DealData> GetDealData(string startDate);
public List<DealData> GetDealData(string startDate)
{
CultureInfo culture = new CultureInfo("en-GB");
List<DealData> model = Service.GetDealData(Convert.ToDateTime(startDate,culture));
return model;
}