2013-03-05 81 views
-1

我正在学习Knockoutjs并怀疑如何显示observablearray()的值;knockoutjs observablearray not displayed

<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代码::在

我的JS代码

<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> 

已经使用了相同的结构,上面的代码,它完美地工作。

+1

是否有任何javascript错误? – 2013-03-05 16:29:17

+2

你说它工作完美,它确实。你的问题是什么? – Tyrsius 2013-03-05 16:30:45

+0

@Tyrsius - 其他代码完美工作,但没有在上面的示例 – JulioCes 2013-03-05 16:38:47

回答

0

您在$(document).ready函数后缺少右括号。下面更正了片段。注意最后一行的差异:

$(document).ready(function() {   
    ko.applyBindings(new ordemservicoVM()); 
}); 

添加括号后,您的代码开始正常工作。

它实际上在chrome开发工具的控制台中显示“Uncaught SyntaxError:Unexpected end of input”错误。因此,请注意控制台以解决此类问题。