Kendo UI绑定中的问题 [英] Problem in Kendo UI binding

查看:65
本文介绍了Kendo UI绑定中的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在努力将kendo网格绑定到Web API。 Web API托管在Azure辅助角色中(尚未发布)。并且Web API被装饰以便与跨域一起工作,即为Web API启用CORS。



让我们看看我写的代码。



Web API中的操作方法如下所示。



I am struggling in order to bind the kendo grid with Web API. Web API is hosted in the Azure worker role (not yet published). And the Web API is decorated in order to work with the cross domains i.e Enabled CORS for the Web API.

Let us look the code I have written.

Action method in the Web API look like the following.

public JToken Get()

    {
        JToken json = JObject.Parse(
           "{ \"firstName\": \"John\",
           \"lastName\": \"Smith\",
           \"isAlive\": true,
           \"age\": 25, 
           \"height_cm\": 167.6, 
           \"address\":
           {      
               \"streetAddress\": \"21 2nd Street\",
               \"city\": \"New York\",
               \"state\": \"NY\",
               \"postalCode\": \"10021-3100\"    
           }, 
           \"phoneNumbers\": 
           [{ 
               \"type\": \"home\", 
               \"number\": \"212 555-1234\"
           },        
           { 
               \"type\": \"office\",  
               \"number\": \"646 555-4567\" 
           }]
           }"
        );
        return json;
    }





当我执行这个web api时,我们将获得IP地址为127.0.0.1的仿真器我使用了控制器TestController。



当我在浏览器中执行上面的api时,我完全得到了JSON数据,但当我使用相同的绑定时网格,都是徒劳的。



用于绑定数据的代码是





When I execute this web api we will get the emulator with the IP address as "127.0.0.1" and I used the controller "TestController".

When I execute the above api in the browser, I am getting the JSON data perfectly, but when I use the same to bind the grid, all is vain.

The code used to bind the data is

$("#DivId").kendoGrid({
                dataSource: {
                    type: "json",
                    transport: {
                        read: {
                            url: "http://127.0.0.1/test",
                            dataType: "json"
                        }
                    },
                },
                height: 500,
                scrollable: true,
                selectable: true
            });





我得到一个例外,Undefined不是一个对象。



请提供解决方案。



I am getting an exception of "Undefined is not an object".

Please provide the solution.

推荐答案

#DivId)。kendoGrid({
dataSource:{
类型: json
transport:{
读取:{
url: http://127.0.0.1/test
dataType: json
}
},
},
height: 500
可滚动: true
可选: true
});
("#DivId").kendoGrid({ dataSource: { type: "json", transport: { read: { url: "http://127.0.0.1/test", dataType: "json" } }, }, height: 500, scrollable: true, selectable: true });





我得到Undefined不是对象的例外。



请提供解决方案。



I am getting an exception of "Undefined is not an object".

Please provide the solution.


最后,经过长时间的努力,我得到了解决方案:(。

我在使用kendo网格时发现了一件奇怪的事情。每当我们使用项目中的模型并将模型返回到kendogrid的数据源时,它就会在内部为它创建一个模型。当我使用上面的示例json时,它(kendogrid)不会为要绑定的网格创建模型。因此问题就出现了。

最后,我得出结论,在数据源(kendo网格)中有一个架构/模型更好。过去我没有:(。
Finally, after a long struggle i got the solution :(.
I find a strange thing when working with the kendo grid. Whenever we work with the models inside our project and returned the model to the datasource of the kendogrid, it internally creates a model for it. As i worked with sample json as above, it (kendogrid) doesn't create the model for the grid to bind. Hence the problem occurs.
Eventually, what i concluded that it is better to have a schema/model in the datasource (kendo grid). Past i didn't :(.


这篇关于Kendo UI绑定中的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆