2

问题定义:

我有一个 ExpandoObject,我需要将其转换为“客户”类型之类的类型,问题没有实现,我想知道我应该使用 javascript 接近服务器端还是客户端,我可以通过两种方式实现我想要的,但这是更有效更省时?

服务器端方法:

public IEnumerable<T> Convert<T>(dynamic self)
{
    List<T> model = new List<T>();
    var jsSerializer = new JavaScriptSerializer();
    foreach (var obj in self)
    {
        model.Add(jsSerializer.ConvertToType<T>(obj));
    }
    return model.AsEnumerable();
}

客户端方法:

var model = [];
data.forEach(function (item) {
    var property = [];
    item.forEach(function (pair) {
        property[pair.Key] = pair.Value;
    });
    model.push(property);
});

二手 ORM: Rob Conery 的 Massive

原始回复(无转换):

[[{“Key”:“ID”,“Value”:2},{“Key”:“customerID”,“Value”:1},{“Key”:“orderID”,“Value”:1}, { "Key": "address", "Value": "25 Ibrahim Nagy Street, NasrCity, Cairo" }, { "Key": "deliveryDateTime", "Value": "/Date(1381528800000)/" }, {" Key": "deliveryPersonnelID", "Value": 1 }], [{ "Key": "ID", "Value": 3 }, { "Key": "customerID", "Value": 2 }, {" Key": "orderID", "Value": 2 }, { "Key": "address", "Value": "14 Ibrahim Nagy Street, NasrCity, Cairo" }, { "Key": "deliveryDateTime", "Value “:"/Date(1386972000000)/" }, { "Key": "deliveryPersonnelID", "Value": 2 }], [{ "Key": "ID", "Value": 4 }, { "Key": " customerID", "Value": 1 }, { "Key": "orderID", "Value": 3 }, { "Key": "address", "Value": "30 Abbas Akad Street, NasrCity, Cairo" } , { "Key": "deliveryDateTime", "Value": "/Date(1387922400000)/" }, { "Key": "deliveryPersonnelID", "Value": 2 }], [{ "Key": "ID" , "值": 5 }, { "Key": "customerID", "Value": 3 }, { "Key": "orderID", "Value": 4 }, { "Key": "address", "价值”: ”25 Hassan Maamoon Street, NasrCity, Cairo" }, { "Key": "deliveryDateTime", "Value": "/Date(1388354400000)/" }, { "Key": "deliveryPersonnelID", "Value": 3 }] ]

4

1 回答 1

0

我决定做转换客户端,我不知道这对我来说是否合适,我的意思是让客户端做一些工作,也不是很辛苦,那为什么要浪费时间服务器端呢?

于 2013-10-14T14:18:48.600 回答