0
我正在使用KO將一個對象綁定到perticular div。以下是我的代碼。KO綁定問題
<div>
<label>Name</label>
<input type="text" data-bind="value: name" />
</div>
<div id="testDiv" style="border:solid red">
<label for="txtProductName">Product Name</label>
<input type="text" id="txtProductName" name="txtProductName" data-bind="value: ProductName"/>
</div>
@section scripts{
<script src="~/Scripts/knockout-2.1.0.js"></script>
<script type="text/javascript">
$(function() {
var ViewModel = function() {
var self = this;
self.name = ko.observable("Hemant");
self.age = ko.observable(50);
self.address = ko.observable("Pune");
};
var vm = new ViewModel();
ko.applyBindings(vm);
var product = {
ProductName: ko.observable(),
Price: ko.observable(),
Desc: ko.observable()
};
ko.applyBindings(product, $('#testDiv')[0]);
});
</script>
}
'名稱' 字段是否正確連接。但我無法綁定'ProductName'。獲取以下錯誤信息
Message: TypeError: 'ProductName' is undefined;
你能幫忙嗎? Registers, Hemant