I will be using Knockoutjs in the project recently, so today I first studied the environment setup of Knockoutjs and conducted a simple test.
First go to http://knockoutjs.com/index.html to download the latest version of Knockoutjs. The author downloaded knockout-2.2.0.js here. Then create a new .html file and add the following statement to the html document to import this js:
At this point we can already write Knockoutjs code. Let's take printing "Hello World!!" as an example and write the following code:
Then use the browser to open this html file, you can see "Hello World!!" words.
In the above code:
A span is defined and data-bind is used to bind helloWorld to the span , so that the content in span is the content in the helloWorld variable.
An AppViewModel is defined in the script, and then a variable is defined for it: helloWorld, whose value is: Hello World!!, and then the ko.applyBindings() method is used to activate the AppViewModel so that this content can be seen on the web page.
The above is just a very simple example using Knockoutjs. During the process of running this example, a small problem occurred, and I am not sure why. The code written before is:
I put