2014-02-21 35 views
0

下面是我的代碼,我嘗試使用knockout.js創建表格,但它不工作。表格根本不會生成。無法使用knockout.js創建表格

<html> 
<head> 
<title>Welcome to Collab-Todo</title> 
<meta name="layout" content="main" /> 
</head> 
<body> 
<h style="margin-left:px;">Welcome to Collab-Todo</h> 
<p style="margin-left:px;width:%"> 
Welcome to the Collab-Todo application. This application was built 
as part of the Apress Book, "Beginning Groovy and Grails." 
Functionally, the application is a collaborative "To-Do" 
list that allows users and their buddies to jointly 
manage "To-Do" tasks.</p><br /> 
<p style="margin-left:px;width:%">Building the Collab-Todo 
application is used to walk the user through using Grails . to 
build an application. Below is a list of controllers that are 
currently deployed in this application. Click on each to execute 
its default action:</p> 
<br /> 
<div class="dialog" style="margin-left:px;width:%;"> 
<ul> 
Hi Hello Word 
</ul> 
</div> 
Test 
         <table> 
          <thead> 
           <tr> 
            <th class="checkbox no-padding"> 
             <label> 
              <input type="checkbox" /> 
             </label> 
            </th> 
            <th> 
            300 
            </th> 
            <!-- ko foreach: columns--> 
            <th data-bind="attr: {id: id}"> 
             <div> 
              <div data-bind="html:name"></div>           
             </div> 
            </th> 
            <!-- /ko --> 
           </tr> 
          </thead> 

          <tbody >  
           <tr> 
           </tr> 
          </tbody>  
        </table> 
</body> 
<script type="text/javascript"> 
var myViewModel = { 
    columns:[ 
       {id:'title',name:'Title'}, 
       {id:'documentLanguage',name:'Document Language'}, 
       {id:'documentType',name:'Document Type'}, 
       {id:'expirationDate',name:'Expiration Date'}, 
       {id:'attachmentSize',name:'Attachment Size'}, 
       {id:'targetAccounts',name:'Target Accounts'}, 
       {id:'audienceType',name:'Audience Type'}, 
       {id:'history',name:'History'}, 
       {id:'action',name:'Action'} 
       ] 
}; 
ko.applyBindings(myViewModel); 
</script> 
</html> 

這有什麼錯在淘汰賽的綁定,我試圖創建一個使用,這樣就會產生對列中的數據每行值的行表頭,請幫我這個

+0

凡提及淘汰賽? – christiandev

回答

0

你必須添加對knockout.js的引用。例如:

<script src="http://cdnjs.cloudflare.com/ajax/libs/knockout/3.0.0/knockout-debug.js" type="text/javascript"></script> 
+0

我在標題中包括該行,但它仍然不工作:( – kumar

+0

是的,我沒有注意到,我已經嘗試與http只作爲http://cdnjs.cloudflare.com/ajax/libs/knockout/3.0.0/knockout -debug.js但它不工作svejdar ... – kumar

+0

它對我有用:) http://jsfiddle.net/svejdo1/sDYE6/ –