kendo 网格中组合框的默认值
Default value for combobox in kendo grid
我将组合框添加到 Kendo 网格中,如下例所示:
http://demos.telerik.com/kendo-ui/grid/editing-custom
schema: {
data: "Data",
total: "Total",
errors: "Errors",
model: {
id: "Id",
fields: {
CityId: {
editable: true,
type: "number",
validation: { required: true }
}, ...
columns: [{
field: "CityId",
title: "City",
editor: cityDropDownEditor,
template: "#=City.Name#",
width: 200,
} ...
function cityDropDownEditor(container, options) {
$('<input required data-text-field="CityName" data-value-field="CityId" data-bind="value:' + options.field + '"/>')
.appendTo(container)
.kendoComboBox({
autoBind: true,
dataTextField: "CityName",
dataValueField: "CityId",
filter: "contains",
index: 1,
autocomplete: true,
dataSource: {
transport: {
read:
{
url: "/Contact/GetCities",
type: "POST",
dataType: "json"
}
}
}});
}
如果我单击“添加”按钮,组合框会显示预填充值 0。如果我删除架构中的行 type: "number"
- 组合框会显示带有 CityName 的预填充值,其索引在组合框初始化中设置
.kendoComboBox({
index: 1...
但是当我点击提交时,这个值没有到达后端,我看到了异常。如何为组合框添加正确的默认值?
首先请注意,您已 dataTextField: "CityName", dataValueField: "CityId"
启动了两次,并且认为您在示例中遗漏了一些内容,即架构中的这一部分
fields: {
ProductID: { editable: false, nullable: true },
ProductName: { validation: { required: true } },
Category: { defaultValue: { CategoryID: 3, CategoryName: "Confections"} },
UnitPrice: { type: "number", validation: { required: true, min: 1} }
}
在 category 字段上,他们将默认值设置为 { CategoryID: 1, CategoryName: "Beverages"}
,现在我将其更改为 { CategoryID: 3, CategoryName: "Confections"}。这里运行良好
我将组合框添加到 Kendo 网格中,如下例所示: http://demos.telerik.com/kendo-ui/grid/editing-custom
schema: {
data: "Data",
total: "Total",
errors: "Errors",
model: {
id: "Id",
fields: {
CityId: {
editable: true,
type: "number",
validation: { required: true }
}, ...
columns: [{
field: "CityId",
title: "City",
editor: cityDropDownEditor,
template: "#=City.Name#",
width: 200,
} ...
function cityDropDownEditor(container, options) {
$('<input required data-text-field="CityName" data-value-field="CityId" data-bind="value:' + options.field + '"/>')
.appendTo(container)
.kendoComboBox({
autoBind: true,
dataTextField: "CityName",
dataValueField: "CityId",
filter: "contains",
index: 1,
autocomplete: true,
dataSource: {
transport: {
read:
{
url: "/Contact/GetCities",
type: "POST",
dataType: "json"
}
}
}});
}
如果我单击“添加”按钮,组合框会显示预填充值 0。如果我删除架构中的行 type: "number"
- 组合框会显示带有 CityName 的预填充值,其索引在组合框初始化中设置
.kendoComboBox({
index: 1...
但是当我点击提交时,这个值没有到达后端,我看到了异常。如何为组合框添加正确的默认值?
首先请注意,您已 dataTextField: "CityName", dataValueField: "CityId"
启动了两次,并且认为您在示例中遗漏了一些内容,即架构中的这一部分
fields: {
ProductID: { editable: false, nullable: true },
ProductName: { validation: { required: true } },
Category: { defaultValue: { CategoryID: 3, CategoryName: "Confections"} },
UnitPrice: { type: "number", validation: { required: true, min: 1} }
}
在 category 字段上,他们将默认值设置为 { CategoryID: 1, CategoryName: "Beverages"}
,现在我将其更改为 { CategoryID: 3, CategoryName: "Confections"}。这里运行良好