gpt4 book ai didi

javascript - 绑定(bind) Kendo Grid 与 Knockout : will config in javascript work with

转载 作者:行者123 更新时间:2023-11-30 10:14:24 27 4
gpt4 key购买 nike

我看过一些使用 knockout 绑定(bind)剑道网格的示例,其中网格配置是在 View 模型中定义的。我真的很喜欢这种风格和它允许的干净标记。但是,我似乎无法使用 usekotemplates 选项。

这是我的标记:

<div data-bind='kendoGrid: gridConfig'></div>
<script id="clientRowTemplate" type="text/html">
<tr>
<td data-bind="text: Name"></td>
<td data-bind="text: State"></td>
<td>
<input type="hidden" data-bind="value: Id" />
<a href="#">Edit</a>
<a href="#">Delete</a>
</td>
</tr>
</script>

这是我的 View 模型

var clientListViewModel = function () {

var self = this;
self.clients = ko.observableArray([]);

self.load = function () {
for (var i = 0; i < 9; i++) {
var c = new clientModel();
c.Id = i;
c.Name = 'Name' + i;
c.State = 'NY';
self.clients.push(c);
};
};

self.gridConfig = {
data: self.clients,
datasource: {
data: "data",
schema: {
model: {
fields: {
ID: { type: "number" },
Name: { type: "string" },
State: { type: "string" }
}
}
},
pageSize: 10,
serverPaging: true
},
height: 400,
pageable: true,
selectable: "row",
usekotemplates: true,
rowtemplate: "clientRowTemplate",
};

};

var clientModel = function () {
var self = this;
self.Id = ko.observable(0);
self.Name = ko.observable("").extend({ required: true });
self.State = ko.observable("").extend({ required: true });
};


var vm = new clientListViewModel();
vm.load();
ko.applyBindings(vm);

这是一个 jsfiddle:http://jsfiddle.net/Steve5877/a4kG7/2/

我可以这样绑定(bind)它并仍然使用模板吗?

最佳答案

看起来您只需要注意传递的几个选项的大小写敏感性:

    useKOTemplates: true,
rowTemplate: "clientRowTemplate",

而不是:

    usekotemplates: true,
rowtemplate: "clientRowTemplate",

关于javascript - 绑定(bind) Kendo Grid 与 Knockout : will config in javascript work with,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24688540/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com