我有以下HTML代码
<div id="Main" >
<div id="Clusters" data-bind="foreach: clusters">
<div id="Scenarios" data-bind="foreach: scenarios">
<div id="ChoiceLists" data-bind ="foreach: choicelists" >
<div id="Forwards" data-bind ="foreach: forwards">
<span data-bind="text: code"></span>
<span data-bind="text: desc"></span><input type="radio" data-bind="value: code" /><br />
</div>
</div>
</div>
</div>
</div>
以下是上述html的脚本
$(function(){
var binding;
function MainEntries(data) {
this.code = data.code;
this.desc = data.desc;
this.clusters = ko.observableArray($.map(data.clusters, function (cluster) { return new Cluster(cluster) }));
}
function Cluster(data) {
var self = this;
self.scenarios = ko.observableArray($.map(data.scenarios, function (scenario) { return new Scenario(scenario) }));
}
function Scenario(data) {
this.choicelists = ko.observableArray($.map(data.choicelists, function (choicelist) { return new ChoiceList(choicelist) }));
}
function ChoiceList(data) {
this.forwards = ko.observableArray($.map(data.forwards, function (forward) { return new Forward(forward) }));
}
function Forward(data) {
this.id = ko.observable(data.id);
this.code = ko.observable(data.code);
this.desc = ko.observable(data.desc);
}
function DisplayClusters(selectedCode) {
$.getJSON("/home/clusters", "code=" + selectedCode, function (data) {
binding = new MainEntries(data);
});
}
ko.applyBindings(binding);
});
我正在调用DisplayClusters()并传递代码,以便它会对我的一个服务和显示数据执行json调用但是它会抛出无法找到绑定“cluster”的错误
我确信数据来自服务,它只是不显示...因为这个错误。我绑定的错误是什么?淘汰赛我有点新鲜。