Kendo网格没有在MVVM中加载数据

时间:2014-11-12 12:02:18

标签: c# kendo-grid kendo-mvvm

未在kendo ui网格中加载数据,这是MVC项目,读取的url以json格式返回正确的对象数组。控制台中没有错误,但页面上没有可见的网格。

        $(document).ready(function () {
        var viewModel = kendo.observable(
            {
                isVisible: true,
                Professions: new kendo.data.DataSource({
                    schema: {
                        model: {
                            id: "ProfessionKey"
                        }
                    },
                    batch: true,
                    transport: {
                        read: {
                            url: "Default/GetAllProfessionsJson",
                            dataType: "Json"
                        },
                        parameterMap: function (options, operation) {
                            if (operation !== "read" && options.models) {
                                return { models: kendo.stringify(options.models) };
                            }
                        }
                    }
                })
            }
        );
        kendo.bind($("#grid"), viewModel);
    });

和html是

<div data-role="grid"
 data-toolbar="['create', 'save']"
 data-columns='["ProfessionKey", ProfessionEnglish", "ProfessionFrench", "ProfessionGerman"]'
 data-bind="source: Professions">
</div>

以及以下文件被引用

<link href="@Url.Content("~/Content/kendo/2012.2.710/kendo.common.min.css")" rel="stylesheet" type="text/css" />
<link href="@Url.Content("~/Content/kendo/2012.2.710/kendo.dataviz.min.css")" rel="stylesheet" type="text/css" />
<link href="@Url.Content("~/Content/kendo/2012.2.710/kendo.default.min.css")" rel="stylesheet" type="text/css" />
<script src="@Url.Content("~/Scripts/kendo/2012.2.710/jquery.min.js")"></script>
<script src="@Url.Content("~/Scripts/kendo/2012.2.710/kendo.all.min.js")"></script>
<script src="@Url.Content("~/Scripts/angular.min.js")"></script>

1 个答案:

答案 0 :(得分:0)

var viewModel的范围应该是全局的/在函数之外。