我已经开始学习淘汰赛 API。我写了一小段代码,很简单,但它不起作用。请帮帮我
<h4>People(<span data-bind="text: controls().length"> </span>)</h4>
<ul data-bind="foreach:controls">
<li>
Id: <span data-bind="text: controls.id"></span>
</li>
</ul>
<button data-bind="click:$root.addControls">Add</button>
var Form = function(){
this.controls = [{id:"T1",type:"TextInput"},
{id:"T2",type:"TextInput"}];
this.addControls = function(){
this.controls.push({id:"",type:""})
};
}
var Controls = function(id,type){
this.id = id;
this.type = type;
}
ko.applyBindings(new Form());