Javascript 剑道UI网格组合框在焦点输出时未定义?
我在基诺用户界面网格上工作过,我在网格中添加了一个组合框作为列,它也支持自动完成功能。显然,comboBox工作正常,但当我键入“世界的一半”并将焦点从comboBox单元格中移出时,它显示为“未定义”。我尝试在combobox更改事件中处理它,但它仍然显示未定义的值?下面是我的combobox和grid代码Javascript 剑道UI网格组合框在焦点输出时未定义?,javascript,kendo-ui,kendo-grid,Javascript,Kendo Ui,Kendo Grid,我在基诺用户界面网格上工作过,我在网格中添加了一个组合框作为列,它也支持自动完成功能。显然,comboBox工作正常,但当我键入“世界的一半”并将焦点从comboBox单元格中移出时,它显示为“未定义”。我尝试在combobox更改事件中处理它,但它仍然显示未定义的值?下面是我的combobox和grid代码 函数productDropDownEditor(容器,选项){ $('') .appendTo(容器).kendoComboBox({ 数据源:数据源, 自动绑定:错误, dataTex
函数productDropDownEditor(容器,选项){
$('')
.appendTo(容器).kendoComboBox({
数据源:数据源,
自动绑定:错误,
dataTextField:'ProductName',
dataValueField:'ProductID',
过滤器:“包含”,
建议:是的,
索引:3,
更改:功能(e){
调试器;
var cmb=此;
//selectedIndex为-1表示自定义值
如果(cmb.selectedIndex<0){
cmb.value(0);//或设置为组合框中的第一项
}
},
关闭:功能(e){
调试器;
var cmb=此;
}
});
下面是剑道格网的代码
$(function () {
$("#grid").kendoGrid({
columns: [
{
field: "Products", width: "250px",
editor: productDropDownEditor,
title: "Product",
template: "#=Products.ProductName#",
attributes: {
"class": "select2_single"
}
},
{ field: "PurchasePrice", width: "150px" },
{ field: "PurchaseQuantity", width: "150px" },
{ field: "SaleRate", title: "Sale Rate", width: "150px" },
{ field: "Amount", title: "Amount", width: "150px" },
{ command: "destroy", title: "Delete", width: "110px" },
],
editable: true, // enable editing
pageable: true,
navigatable: true,
sortable: true,
editable: "incell",
toolbar: ["create"], // specify toolbar commands
edit: function (e) {
//debugger;
//// var parentItem = parentGrid.dataSource.get(e.model.PurchaseID);
////e.model.set("ShipCountry", parentItem.Country);
//if (e.model.isNew()) {
// // set the value of the model property like this
// e.model.set("PropertyName", Value);
// // for setting all fields, you can loop on
// // the grid columns names and set the field
//}
},
//editable: "inline",
dataSource: {
serverPaging: true,
requestStart: function () {
kendo.ui.progress($("#loading"), true);
},
requestEnd: function () {
kendo.ui.progress($("#loading"), false);
},
serverFiltering: true,
serverSorting: true,
batch: true,
pageSize: 3,
schema: {
data: "data",
total: "Total",
model: { // define the model of the data source. Required for validation and property types.
id: "Id",
fields: {
PurchaseID: { editable: false, nullable: true },
PurchasePrice: { nullable: true },
PurchaseQuantity: { validation: { required: true, min: 1 } },
SaleRate: { validation: { required: true, min: 1 } },
Amount: { type: "number", editable: false },
Products: {
nullable: false,
validation: { required: true},
defaultValue: {ProductID:1, ProductName:"Googo" },
//from: "Products.ProductName",
parse: function (data) {
debugger;
if (data == null) {
data = { ProductID: 1};
}
return data;
},
type: "object"
}
}
}
},
batch: true, // enable batch editing - changes will be saved when the user clicks the "Save changes" button
change: function (e) {
debugger;
if (e.action === "itemchange" && e.field !== "Amount") {
var model = e.items[0],
type = model.Type,
currentValue = model.PurchasePrice * model.PurchaseQuantity;//formulas[type](model);
if (currentValue !== model.Amount) {
model.Amount = currentValue;
$("#grid").find("tr[data-uid='" + model.uid + "'] td:eq(4)").text(currentValue);
}
//if (e.field == "Products") {
// $("#grid").find("tr[data-uid='" + model.uid + "'] td:eq(0)").text(model.Products);
//}
}
},
transport: {
read: {
url: "@Url.Action("Read", "Purchase")", //specify the URL which should return the records. This is the Read method of the HomeController.
contentType: "application/json",
type: "POST", //use HTTP POST request as by default GET is not allowed by ASP.NET MVC
},
parameterMap: function (data, operation) {
debugger;
if (operation != "read") {
// post the products so the ASP.NET DefaultModelBinder will understand them:
// data.models[0].ProductID = data.models[0].Product.ProductID;
var result = {};
// data.models[0].ProductID = $("#ProductDropDown").val();
for (var i = 0; i < data.models.length; i++) {
var purchase = data.models[i];
for (var member in purchase) {
result["purchaseDetail[" + i + "]." + member] = purchase[member];
}
}
return result;
} else {
var purchaseID = $("#hdnPurchaseId").val();
//output = '{ purchaseID: ' + purchaseID + '}';
data.purchaseID = purchaseID; // Got value from MVC view model.
return JSON.stringify(data)
}
}
}
},
}).data("kendoGrid");
$(函数(){
$(“#网格”).kendoGrid({
栏目:[
{
字段:“产品”,宽度:“250px”,
编辑:productDropDownEditor,
标题:“产品”,
模板:“#=Products.ProductName”,
属性:{
“类别”:“选择2个单选”
}
},
{字段:“PurchasePrice”,宽度:“150px”},
{字段:“PurchaseQuantity”,宽度:“150px”},
{字段:“销售率”,标题:“销售率”,宽度:“150px”},
{字段:“数量”,标题:“数量”,宽度:“150px”},
{命令:“销毁”,标题:“删除”,宽度:“110px”},
],
可编辑:true,//启用编辑
pageable:对,
可导航:是的,
可排序:是的,
可编辑:“incell”,
工具栏:[“创建”],//指定工具栏命令
编辑:功能(e){
//调试器;
////var parentItem=parentGrid.dataSource.get(e.model.PurchaseID);
////e、 model.set(“ShipCountry”,parentItem.Country);
//如果(e.model.isNew()){
////如下设置模型属性的值
//e.model.set(“PropertyName”,值);
////要设置所有字段,可以循环
////网格列的名称和设置字段
//}
},
//可编辑:“内联”,
数据源:{
对,,
requestStart:函数(){
kendo.ui.progress($(“#加载”),true;
},
requestEnd:函数(){
kendo.ui.progress($(“#加载”),false;
},
是的,
对,,
批次:对,
页面大小:3,
模式:{
数据:“数据”,
总计:“总计”,
模型:{//定义数据源的模型。验证和属性类型需要此模型。
id:“id”,
字段:{
PurchaseID:{editable:false,nullable:true},
PurchasePrice:{nullable:true},
PurchaseQuantity:{验证:{必需:真,最小:1}},
SaleRate:{验证:{必需:true,min:1},
金额:{type:“number”,可编辑:false},
产品:{
可为空:false,
验证:{必需:true},
默认值:{ProductID:1,ProductName:“Googo”},
//发件人:“Products.ProductName”,
解析:函数(数据){
调试器;
如果(数据==null){
数据={ProductID:1};
}
返回数据;
},
类型:“对象”
}
}
}
},
批处理:true,//启用批处理编辑-当用户单击“保存更改”按钮时,将保存更改
更改:功能(e){
调试器;
如果(e.action==“itemchange”&&e.field!==“Amount”){
var模型=e.项目[0],
type=model.type,
currentValue=model.PurchasePrice*model.PurchaseQuantity;//公式[类型](模型);
如果(currentValue!==型号金额){
型号。金额=当前值;
$(“#网格”).find(“tr[data uid='”+model.uid+']td:eq(4)”.text(currentValue);
}
//如果(如字段==“产品”){
//$(“#网格”).find(“tr[data uid='”+model.uid+']td:eq(0)”.text(model.Products);
//}
}
},
运输:{
阅读:{
url:@url.Action(“读取”、“购买”),//指定应返回记录的url。这是HomeController的读取方法。
contentType:“应用程序/json”,
键入:“POST”//使用HTTP POST请求,因为ASP.NET MVC默认不允许GET
},
parameterMap:功能(数据、操作){
调试器;
如果(操作!=“读取”){
//发布产品,以便ASP.NET DefaultModelBinder能够理解它们:
//data.models[0].ProductID=data.models[0].Product.ProductID;
$(function () {
$("#grid").kendoGrid({
columns: [
{
field: "Products", width: "250px",
editor: productDropDownEditor,
title: "Product",
template: "#=Products.ProductName#",
attributes: {
"class": "select2_single"
}
},
{ field: "PurchasePrice", width: "150px" },
{ field: "PurchaseQuantity", width: "150px" },
{ field: "SaleRate", title: "Sale Rate", width: "150px" },
{ field: "Amount", title: "Amount", width: "150px" },
{ command: "destroy", title: "Delete", width: "110px" },
],
editable: true, // enable editing
pageable: true,
navigatable: true,
sortable: true,
editable: "incell",
toolbar: ["create"], // specify toolbar commands
edit: function (e) {
//debugger;
//// var parentItem = parentGrid.dataSource.get(e.model.PurchaseID);
////e.model.set("ShipCountry", parentItem.Country);
//if (e.model.isNew()) {
// // set the value of the model property like this
// e.model.set("PropertyName", Value);
// // for setting all fields, you can loop on
// // the grid columns names and set the field
//}
},
//editable: "inline",
dataSource: {
serverPaging: true,
requestStart: function () {
kendo.ui.progress($("#loading"), true);
},
requestEnd: function () {
kendo.ui.progress($("#loading"), false);
},
serverFiltering: true,
serverSorting: true,
batch: true,
pageSize: 3,
schema: {
data: "data",
total: "Total",
model: { // define the model of the data source. Required for validation and property types.
id: "Id",
fields: {
PurchaseID: { editable: false, nullable: true },
PurchasePrice: { nullable: true },
PurchaseQuantity: { validation: { required: true, min: 1 } },
SaleRate: { validation: { required: true, min: 1 } },
Amount: { type: "number", editable: false },
Products: {
nullable: false,
validation: { required: true},
defaultValue: {ProductID:1, ProductName:"Googo" },
//from: "Products.ProductName",
parse: function (data) {
debugger;
if (data == null) {
data = { ProductID: 1};
}
return data;
},
type: "object"
}
}
}
},
batch: true, // enable batch editing - changes will be saved when the user clicks the "Save changes" button
change: function (e) {
debugger;
if (e.action === "itemchange" && e.field !== "Amount") {
var model = e.items[0],
type = model.Type,
currentValue = model.PurchasePrice * model.PurchaseQuantity;//formulas[type](model);
if (currentValue !== model.Amount) {
model.Amount = currentValue;
$("#grid").find("tr[data-uid='" + model.uid + "'] td:eq(4)").text(currentValue);
}
//if (e.field == "Products") {
// $("#grid").find("tr[data-uid='" + model.uid + "'] td:eq(0)").text(model.Products);
//}
}
},
transport: {
read: {
url: "@Url.Action("Read", "Purchase")", //specify the URL which should return the records. This is the Read method of the HomeController.
contentType: "application/json",
type: "POST", //use HTTP POST request as by default GET is not allowed by ASP.NET MVC
},
parameterMap: function (data, operation) {
debugger;
if (operation != "read") {
// post the products so the ASP.NET DefaultModelBinder will understand them:
// data.models[0].ProductID = data.models[0].Product.ProductID;
var result = {};
// data.models[0].ProductID = $("#ProductDropDown").val();
for (var i = 0; i < data.models.length; i++) {
var purchase = data.models[i];
for (var member in purchase) {
result["purchaseDetail[" + i + "]." + member] = purchase[member];
}
}
return result;
} else {
var purchaseID = $("#hdnPurchaseId").val();
//output = '{ purchaseID: ' + purchaseID + '}';
data.purchaseID = purchaseID; // Got value from MVC view model.
return JSON.stringify(data)
}
}
}
},
}).data("kendoGrid");