gpt4 book ai didi

mvvm - 剑道数据源 : How to define "Computed" Properties for data read from remote odata source

转载 作者:行者123 更新时间:2023-12-02 06:19:26 27 4
gpt4 key购买 nike

情况:

  • 剑道数据源

    var ordersDataSource = new kendo.data.DataSource({
    type: "odata",
    transport: {
    read: {
    url: "http://localhost/odata.svc/Orders?$expand=OrderDetails"
    }
    },
    schema: {
    type: "json",
    data: function(response){
    return response.value;
    }
    total: function(response){
    return response['odata.count'];
    }
    },
    serverPaging: true,
    serverFiltering: true,
    serverSorting: true
    })
  • 从odata源读取的json数据是这样的:

    {
    odata.metadata: "xxxx",
    odata.count: "5",
    value: [
    {
    OrderId: 1,
    OrderedDate: "2013-02-20",
    OrderInfoA: "Info A",
    OrderInfoB: "Info B"
    OrderDetails: [
    {
    OrderDetailId: 6,
    OrderDetailInfoC: "Info C",
    OrderDetailInfoD: "Info D"
    },
    {
    //Another OrderDetail's data
    }
    ]
    },
    {
    // Another Order's data
    }
    ]
    }

问题 1:

1.如果我想定义一个“计算”属性:OrderedDateRelative,它应该是今天(2013-02-25)和订单创建日期(2013- 02-20),比如:“5 天前”,我如何在客户端实现这一点?

问题 1 的答案:http://jsbin.com/ojomul/7/edit

问题 2 --更新--

2.每个订单都有其嵌套的属性OrderDetails,那么是否可以为嵌套的OrderDetails 属性定义一个计算字段?例如:每个 OrderDetail 的 OrderDetailInfoCAndD,值应该类似于:OrderDetailInfoC + OrderDetailInfoD,即“信息 C 信息 D”?

谢谢,

院长

最佳答案

您可以通过指定数据源的模型来创建计算字段:

  dataSource = new kendo.data.DataSource({
data: [
{ first: "John", last: "Doe" },
{ first: "Jane", last: "Doe" }
],
schema: {
model: {
// Calculated field
fullName: function() {
return this.get("first") + " " + this.get("last");
}
}
}
});

这是一个现场演示:http://jsbin.com/ojomul/1/edit

关于mvvm - 剑道数据源 : How to define "Computed" Properties for data read from remote odata source,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15069916/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com