我在学习Knockoutjs,有疑问如何显示一个observablearray()的值;
我的 JS 代码在:
<script>
function Cliente(nome, CGC) {
this.Nome = nome;
this.Cgccfo = CGC;
};
function ordemservicoVM() {
self = this;
self.pessoas = ko.observableArray([
new Cliente("ValueOne", "ValueTwo")
]);
};
$(document).ready(function () {
ko.applyBindings(new ordemservicoVM());
}
</script>
html代码:
<table>
<thead>
<tr>
<th>Nome</th>
<th>CGC</th>
</tr>
</thead>
<tbody data-bind="foreach: pessoas" >
<tr>
<td data-bind="text: Nome"></td>
<td data-bind="text: Cgccfo"></td>
</tr>
</tbody>
</table>
已经使用了与上述代码相同的结构,并且运行良好。