gpt4 book ai didi

kendo-ui - 如何在 Kendoui 中获取字段类型?

转载 作者:行者123 更新时间:2023-12-01 09:55:44 25 4
gpt4 key购买 nike

有没有这样的方法dataSource.getFieldType(field)在数据源中:

var dataSource = new kendo.data.DataSource({
// somethings here,
schema : {
model : {
post_id : {type: "number" },
post_title : {type:"string"},
post_date : {type:"date"}
}
}
});

var fieldType = dataSource.getFieldType("post_title"); // it should return string

最佳答案

您应该定义一个 getFieldType功能如下:

function getFieldType(dataSource, field) {
return dataSource.options.schema.model.fields[field].type;
}

并使用它是:

var fieldType = getFieldType(dataSource, "post_title");

或者,您可以扩展 KendoUI DataSource 来定义一个名为 getFieldType 的新方法。通过做:

kendo.data.DataSource.prototype.getFieldType = function(field) {
return this.options.schema.model.fields[field].type;
}

并使用它是:

var fieldType = dataSource.getFieldType("post_title");

使用 DataSource 扩展在此处检查版本:

$(document).ready(function() {
kendo.data.DataSource.prototype.getFieldType = function(field) {
return this.options.schema.model.fields[field].type;
}

$("#show").on("click", function() {
var ds = $("#grid").data("kendoGrid").dataSource;
alert("Freight: " + ds.getFieldType("Freight"));
});


$("#grid").kendoGrid({
dataSource: {
type: "odata",
transport: {
read: "http://demos.telerik.com/kendo-ui/service/Northwind.svc/Orders"
},
schema: {
model: {
fields: {
OrderID: { type: "number" },
Freight: { type: "number" },
ShipName: { type: "string" },
OrderDate: { type: "date" },
ShipCity: { type: "string" }
}
}
},
pageSize: 20,
serverPaging: true,
serverFiltering: true,
serverSorting: true
},
height: 550,
pageable: true,
columns: [
{
field:"OrderID",
filterable: false
},
"Freight",
{
field: "OrderDate",
title: "Order Date",
format: "{0:MM/dd/yyyy}"
},
{
field: "ShipName",
title: "Ship Name"
},
{
field: "ShipCity",
title: "Ship City"
}
]
});
});
html { 
font-size: 12px;
font-family: Arial, Helvetica, sans-serif;
}
<link rel="stylesheet" href="http://cdn.kendostatic.com/2014.3.1316/styles/kendo.common.min.css" />
<link rel="stylesheet" href="http://cdn.kendostatic.com/2014.3.1316/styles/kendo.default.min.css" />
<script src="http://cdn.kendostatic.com/2014.3.1316/js/jquery.min.js"></script>
<script src="http://cdn.kendostatic.com/2014.3.1316/js/kendo.all.min.js"></script>

<button id="show" class="k-button">Show Freight type</button>
<div id="grid"></div>

关于kendo-ui - 如何在 Kendoui 中获取字段类型?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28172421/

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