这个想法是我有日历控制,我可以从中选择不同的日期。根据选择的日期,我对 WCF 服务 (GetDealData()) 进行 ajax 调用以获取一些数据集。请问有人可以看看这里有什么问题吗?这两天我有点疯狂地试图弄清楚为什么我的 GetRemoteData() 方法每次执行 OnDateChange 方法时都会传递相同的日期(即 2012 年 10 月 25 日),即使我在日历控件上选择了不同的日期也是如此。是否与未正确分配 json 数据有关?
$('#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;
}