我可能會問這是在這個環節上給予約Knockoutjs問題聽起來很傻: http://jsfiddle.net/VR5aa/ 的代碼給出如下:Claryfying約淘汰賽JS
HTML
<!-- This is a *view* - HTML markup that defines the appearance of your UI -->
<p>First name: <strong data-bind="text: firstName"></strong></p>
<p>Last name: <strong data-bind="text: lastName"></strong></p>
<p>First name: <input data-bind="value: firstName" /></p>
<p>Last name: <input data-bind="value: lastName" /></p>
<p>Full name: <strong data-bind="text: fullName"></strong></p>
和JS :
// This is a simple *viewmodel* - JavaScript that defines the data and behavior of your UI
function AppViewModel() {
this.firstName = ko.observable("Bert");
this.lastName = ko.observable("Bertington");
this.fullName = ko.computed(function() {
return this.firstName() + " " + this.lastName();
}, this);
}
// Activates knockout.js
ko.applyBindings(new AppViewModel());
什麼讓我在淘汰賽中困惑是使用括號。例如在文本綁定中,我們可以使用text:firstName(),但它也可以使用。 我也嘗試以下操作:
console.log(typeof this.firstName); //returns function
console.log(typeof this.firstName()); //returns string
所以請有人可以詳細()在淘汰賽JS的使用。由於
感謝亞當開始簡單的視頻,您可以檢查該播放列表。我清楚地知道我的困惑。 – Pant