2015-06-02 76 views
0

爲什麼這個工作(把JSON直接進入觀察到的功能)劍道觀察到的可變


<ul data-template="ul-template" data-bind="source: Orders"> 
</ul> 
<script id="ul-template" type="text/x-kendo-template"> 
    <li> 
     OrderNo: <span data-bind="text: OrderNo"></span> 
     name: <span data-bind="text: CustName"></span> 
    </li> 
</script> 
<script> 

var viewModel = kendo.observable({Orders:[ 
{"OrderID":"437","OrderNo":"1211","CustCode":"1022","CustName":"Kingmen"},{"OrderID":"438","OrderNo":"1212","CustCode":"1023","CustName":"Fredrick"} 
]}); 

kendo.bind($("ul"), viewModel); 
</script> 

但這代碼不起作用(在一個變量與JSON數據)。沒有輸出。


<ul data-template="ul-template" data-bind="source: Orders"> 
</ul> 
<script id="ul-template" type="text/x-kendo-template"> 
    <li> 
     OrderNo: <span data-bind="text: OrderNo"></span> 
     name: <span data-bind="text: CustName"></span> 
    </li> 
</script> 
<script> 

var orderData = '{Orders:[ 
{"OrderID":"437","OrderNo":"1211","CustCode":"1022","CustName":"Kingmen"},{"OrderID":"438","OrderNo":"1212","CustCode":"1023","CustName":"Fredrick"} 
]}'; 
var viewModel = kendo.observable(orderData); 

kendo.bind($("ul"), viewModel); 
</script> 

保羅

回答

0

你orderData變量是一個字符串,而不是JSON。刪除引號。

var orderData = {Orders:[]} 

var orderData = '{Orders:[]}' 

fiddle

+0

謝謝你的很好的例子! – user1544704