未捕获的 TypeError: Object [object Object] has no method 'dataBind' 获取此错误需要将数据绑定与表示 (HTML) 分离
<script type="text/javascript" src="/Scripts/knockout-2.1.0.js"></script>
<script type="text/javascript" src="/Scripts/jquery-1.7.2.js"></script>
Choose a ticket class:
<select id='tickets'></select>
<p id='ticketOutput'></p>
<script id="ticketTemplate" type="text/x-jquery-tmpl">
{{if chosenTicket}}
You have chosen <b>${ chosenTicket().name }</b>
($${ chosenTicket().price })
<button data-bind="click: resetTicket">Clear</button>
{{/if}}
</script>
<script type="text/javascript">
var viewModel = {
tickets: [
{ name: "Economy", price: 199.95 },
{ name: "Business", price: 449.22 },
{ name: "First Class", price: 1199.99 }
],
chosenTicket: ko.observable(),
resetTicket: function () { this.chosenTicket(null) }
};
$('#tickets').dataBind({
Uncaught TypeError: Object [object Object] has no method 'dataBind'
options: 'tickets',
optionsCaption: "'Choose...'",
optionsText: "'name'",
value: 'chosenTicket'
});
$('#ticketOutput').dataBind({ template: "'ticketTemplate'" });
ko.applyBindings(viewModel);
</script>