如何将对象列表传递给数据对象..? [英] How to pass list of object to data object..?

查看:63
本文介绍了如何将对象列表传递给数据对象..?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

function myfunction(){

var objTask = {

SenderID:4,// userid

ScheduleDate:2016年12月1日(周四)

}

var pass = [];

$ .ajax({

type: POST,

url:http:// localhost:49534 / TaskManagement.svc / TaskList,

数据:JSON.stringify(objTask),

contentType:application / json; charset = utf-8,

dataType:json,

成功:函数(数据,状态,jqXHR,结果){

for(i = 0; i< data.length; i ++){

pass = [{title:data [i] .TaskName, 开始:'2016年12月10日星期六16:35:55 GMT + 0530(印度标准时间)',className:'bg-purple'}];

}

}

});

alert(Loding ...);

返回通行证;

}

 





我尝试了什么:



当上面的代码是我正在尝试...而成功函数重新调整值列表....但它们只返回最后一个列表值...如何传递值列表..plz help

解决方案

.ajax({

类型:POST ,

url:http:// localhost:49534 / TaskManagement.svc / TaskList,

数据:JSON.stringify(objTask),

contentType:application / json; charset = utf-8,

dataType:json,

成功:函数(数据,状态,jqXHR,结果){

for(i = 0; i< data.length; i ++){

pass = [{title:data [i] .TaskName,start:'2016年12月10日星期六16: 35:55 GMT + 0530(印度标准时间)',className:'bg-purple'}];

}

}

});

alert(Loding ...);

返回通行证;

}

 





我的尝试:



当上面的代码是我正在尝试...并且成功函数重新调整值列表....但是它们只返回最后一个列表值...如何传递值列表... plz help


在每次迭代中,您的代码都将pass设置为一个包含单个项目的数组,该项目是当前项目,因此每次迭代都会在结束之前替换该数组,这意味着您最终只能使用最后一个在循环中,您需要在现有循环中添加单个项目数组。



 pass.push({title:data [i] .TaskName,start:'2016年12月10日星期六16 :35:55 GMT + 0530(印度标准时间)',className:'bg-purple'}); 





以上我正在使用push添加到阵列中,我正在推送单个项目



{...}



不同于原始代码,它设置了一个带有单个项目的数组



[{...}]


(项目由{}定义,数组由[]定义)


pass [i] = [ {title:data [i] .TaskName,start:'Sat Dec 10 2016 16:35:55 GMT + 0530(India Standard Time)',className:'bg-purple'}];

function myfunction() {
var objTask = {
SenderID: 4, //userid
ScheduleDate: "01 Dec 2016 (Thu)"
}
var pass =[];
$.ajax({
type: "POST",
url: "http://localhost:49534/TaskManagement.svc/TaskList",
data: JSON.stringify(objTask),
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (data, status, jqXHR, result) {
for (i = 0; i < data.length; i++) {
pass = [{"title": data[i].TaskName, "start": 'Sat Dec 10 2016 16:35:55 GMT+0530 (India Standard Time)',"className": 'bg-purple'}];
}
}
});
alert("Loding...");
return pass;
}



What I have tried:

when the above code is i am trying...and the success function retun list of values ....but they return only last list value...how to pass list of values..plz help

解决方案

.ajax({
type: "POST",
url: "http://localhost:49534/TaskManagement.svc/TaskList",
data: JSON.stringify(objTask),
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (data, status, jqXHR, result) {
for (i = 0; i < data.length; i++) {
pass = [{"title": data[i].TaskName, "start": 'Sat Dec 10 2016 16:35:55 GMT+0530 (India Standard Time)',"className": 'bg-purple'}];
}
}
});
alert("Loding...");
return pass;
}



What I have tried:

when the above code is i am trying...and the success function retun list of values ....but they return only last list value...how to pass list of values..plz help


In every iteration your code is setting pass to be an array that contains a single item which is the current item, so each iteration replaces the array before end meaning you end up with only the last one in the loop. Instead in your loop you need to add a single item to the existing array.

pass.push ({"title": data[i].TaskName, "start": 'Sat Dec 10 2016 16:35:55 GMT+0530 (India Standard Time)',"className": 'bg-purple'});



Above I am using push to add to the array and I am pushing a single item

{ ... }

unlike your original code which was setting an array with a single item

[{ ... }]

(an item is defined by {} and an array by [])


pass[i] = [{"title": data[i].TaskName, "start": 'Sat Dec 10 2016 16:35:55 GMT+0530 (India Standard Time)',"className": 'bg-purple'}];


这篇关于如何将对象列表传递给数据对象..?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆