Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/docker/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/database/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Kendo ui KendoUI网格添加新记录弹出窗口,其中包含架构中未定义的dropdownlist_Kendo Ui_Kendo Grid - Fatal编程技术网

Kendo ui KendoUI网格添加新记录弹出窗口,其中包含架构中未定义的dropdownlist

Kendo ui KendoUI网格添加新记录弹出窗口,其中包含架构中未定义的dropdownlist,kendo-ui,kendo-grid,Kendo Ui,Kendo Grid,我使用一个编辑器模板显示一个下拉列表,通过一个剑道网格弹出窗口。填充网格的初始查询使用/?$expand=ContactType,其中ContactType是查找值,Contact是父记录。这工作正常,网格显示正确的数据和相关的联系人类型。单击edit也可以工作,因为我已经定义了一个编辑器模板来显示下拉列表,并且在下拉列表中选择了正确的值 然而,我的问题是添加一个新记录。当我单击添加时,我得到 ContactType未定义 这是有意义的,因为在datagrid的datsource模式中没有明确定

我使用一个编辑器模板显示一个下拉列表,通过一个剑道网格弹出窗口。填充网格的初始查询使用
/?$expand=ContactType
,其中
ContactType
是查找值,
Contact
是父记录。这工作正常,网格显示正确的数据和相关的
联系人类型
。单击
edit
也可以工作,因为我已经定义了一个编辑器模板来显示下拉列表,并且在下拉列表中选择了正确的值

然而,我的问题是添加一个新记录。当我单击添加时,我得到

ContactType未定义

这是有意义的,因为在datagrid的datsource模式中没有明确定义
ContactType
,因为我使用的是expand。我可以将
ContactType
添加到模型定义中,没有问题,错误也会消失-但是发送更新时
ContactType
是一个空字符串,并且不会拾取实际选择的值
ContactType
是与
Contact
相关的实体,据我所知,您无法定义具有相关实体的模型。它们确实具有Hierarchy数据源,但仅适用于treeview

因此,在网格的弹出编辑器中给定一个下拉列表,您如何获得
addnew
来发送所选的下拉值

这里有一些代码,TIA需要帮助吗

<script id="popup_editor" type="text/x-kendo-template">
    <div class="k-edit-label">
    <label for="firstName">First Name</label>
    </div>
    <input type="text" name="firstName"  data-bind="value:firstName" />

    <div class="k-edit-label">
    <label for="middleName">Middle Name</label>
    </div>
    <input type="text" name="middleName"  data-bind="value:middleName" />

    <div class="k-edit-label">
    <label for="lastName">Last Name</label>
    </div>
    <input type="text" name="lastName"  data-bind="value:lastName" />

    <input name="ContactType" data-source="myDropdownDS" data-text-field="name"
    data-value-field="__KEY" data-bind="value:ContactType.__KEY" data-role="dropdownlist" />
</script>

<script>

    //Local
    var crudServiceBaseUrl = "http://127.0.0.1:8081/cors/";
    var myGridDS = new kendo.data.DataSource({
        type : "json",
        transport : {
            read : {
                url : crudServiceBaseUrl + "Contact" + "/?$expand=ContactType",
                dataType : "json",
                type : "GET",
                complete : function(jqXHR, textStatus) {
                    textStatus = "read";
                }
            },
            update : {
                url : crudServiceBaseUrl + "Contact" + "/?$method=update",
                dataType : "json",
                type : "POST",
                complete : function(jqXHR, textStatus) {
                    textStatus = "update";
                }
            },
            destroy : {
                url : crudServiceBaseUrl + "Contact" + "/?$method=delete",
                type : "GET",
                complete : function(jqXHR, textStatus) {
                    textStatus = "destroy";
                }
            },
            create : {
                url : crudServiceBaseUrl + "Contact" + "/?$method=update",
                dataType : "json",
                type : "POST",
                complete : function(jqXHR, textStatus) {
                    textStatus = "create";
                }
            },
            errors : function(response) { 
                var errorData = $.parseJSON(e.responseText);
                alert(errorData.errorMessage);
                //$("#loading").innerHtml = "error";
            },
            parameterMap : function(options, operation) {
                if (operation == "create") { 
                    return JSON.stringify({
                        "__ENTITIES" : options.models
                    });
                } else if (operation == "update") { 
                    var isEdit = true
                    var myParentEntity = "Contact"
                    var myData = options.models[0];
                    //uri gets added after first edit from Wakanda response, not needed and causes update to fail so delete
                    // delete myData.uri;
                    //

                    configureDataRowRelations(myParentEntity, myData, isEdit)
                    return JSON.stringify({
                        "__ENTITIES" : options.models
                    });
                }

            }
        },
        serverPaging : true,
        serverSorting : true,
        serverFiltering : true,
        batch : true,
        pageSize : 30,
        schema : {
            model : {
                id : "__KEY",
                fields : {
                    __KEY : {
                        type : "string"
                    },
                    __STAMP : {
                        type : "number"
                    },
                    ID : {
                        editable : false,
                        nullable : true
                    },
                    firstName : {
                        type : "string",
                        validation : {
                            required : true
                        }
                    },
                    middleName : {
                        type : "string"
                    },
                    lastName : {
                        type : "string",
                        validation : {
                            required : true
                        }
                    },
                    ContactType : {}
                }
            },
            data : "__ENTITIES"
        }
    });

    var myDropdownDS = new kendo.data.DataSource({
        type : "json",
        transport : {
            read : {
                url : crudServiceBaseUrl + "ContactType",
                dataType : "json",
                type : "GET",
            }
        },
        batch : true,
        pageSize : 30,
        schema : {
            model : {
                id : "__KEY",
                fields : {
                    __KEY : {
                        type : "string"
                    },
                    __STAMP : {
                        type : "number"
                    },
                    ID : {
                        editable : false,
                        nullable : true
                    },
                    name : {
                        type : "string",
                        validation : {
                            required : true
                        }
                    }
                }
            },
            data : "__ENTITIES"
        }
    });



    $('#PopupContactContactTypeGrid').kendoGrid({
        selectable : "row",
        filterable : true,
        pageable : true,
        sortable : true,
        dataSource : myGridDS,
        toolbar : ["create"],
        columns : [{
            field : "ID"
        }, {
            field : "firstName",
            title : "First Name"
        }, {
            field : "middleName",
            title : "Middle Name"
        }, {
            field : "lastName",
            title : "Last Name"
        }, {
            field : "ContactType.name",
            title : "Contact Type"
        }, {
            command : ["edit", "destroy"],
            title : "&nbsp;",
            width : "210px"
        }],
        editable : {
            mode : "popup",
            template : $("#popup_editor").html()
        },

    });

名字
中名
姓
//本地的
var crudServiceBaseUrl=”http://127.0.0.1:8081/cors/";
var myGridDS=new kendo.data.DataSource({
键入:“json”,
运输:{
阅读:{
url:crudServiceBaseUrl+“联系人”+“/?$expand=ContactType”,
数据类型:“json”,
键入:“获取”,
完成:函数(jqXHR,textStatus){
textStatus=“读取”;
}
},
更新:{
url:crudServiceBaseUrl+“联系人”+“/?$method=update”,
数据类型:“json”,
类型:“POST”,
完成:函数(jqXHR,textStatus){
textStatus=“更新”;
}
},
销毁:{
url:crudServiceBaseUrl+“联系人”+“/?$method=delete”,
键入:“获取”,
完成:函数(jqXHR,textStatus){
textStatus=“销毁”;
}
},
创建:{
url:crudServiceBaseUrl+“联系人”+“/?$method=update”,
数据类型:“json”,
类型:“POST”,
完成:函数(jqXHR,textStatus){
textStatus=“创建”;
}
},
错误:函数(响应){
var errorData=$.parseJSON(e.responseText);
警报(errorData.errorMessage);
//$(“#加载”).innerHtml=“错误”;
},
parameterMap:功能(选项、操作){
如果(操作==“创建”){
返回JSON.stringify({
“_实体”:options.models
});
}else if(操作==“更新”){
var isEdit=true
var myParentEntity=“联系人”
var myData=options.models[0];
//uri在Wakanda响应的第一次编辑后添加,不需要,并导致更新失败,因此删除
//删除myData.uri;
//
configureDataRowRelations(myParentEntity、myData、iEdit)
返回JSON.stringify({
“_实体”:options.models
});
}
}
},
对,,
对,,
是的,
批次:对,
页面大小:30,
模式:{
型号:{
id:“\u密钥”,
字段:{
__关键:{
类型:“字符串”
},
__邮票:{
类型:“编号”
},
身份证:{
可编辑:false,
可为空:真
},
名字:{
键入:“字符串”,
验证:{
必填项:true
}
},
中间名:{
类型:“字符串”
},
姓氏:{
键入:“字符串”,
验证:{
必填项:true
}
},
联系人类型:{}
}
},
数据:“\uuuu实体”
}
});
var myDropdownDS=new kendo.data.DataSource({
键入:“json”,
运输:{
阅读:{
url:crudServiceBaseUrl+“联系人类型”,
数据类型:“json”,
键入:“获取”,
}
},
批次:对,
页面大小:30,
模式:{
型号:{
id:“\u密钥”,
字段:{
__关键:{
类型:“字符串”
},
__邮票:{
类型:“编号”
},
身份证:{
可编辑:false,
可为空:真
},
姓名:{
键入:“字符串”,
验证:{