Learning knockout Hello World

Source: Internet
Author: User

Learning knockout Hello World

I just started learning knockout. The content is equivalent to a learning note. In addition, I would like to pay tribute to the official website and like their live example forum, which contains jsfiddle. As for documents and tutorials, there are also some. Included address: knockout. If you are interested, you can take a look.

So, start.

You cannot write a hello World record first. After reading the document, it looks very simple. Step 1 introduce Ko's Js script. Step 2: Create a viewmodel. Step 3: create a simple view and bind it with data-bind. A very simple text binding.
1 <! Doctype HTML> 2 <HTML xmlns = "http://www.w3.org/1999/xhtml"> 3 First write Ko

Check the running result:

Nothing, but the bound data is not displayed. Let's take a look at the document first. It turns out to be a few lines of code. It cannot be missing: myviewmodel = Ko. applybindings (myviewmodel ). Only when the data-bind attribute is available can it be recognized by the browser. Its function can be understood as activating knockout. The name after the text is followed by this line of code will prompt intelligently. So the clever way is to write the VM, then write it, and finally write V, there will be smart prompts when writing v.
1 <! Doctype HTML> 2 <HTML xmlns = "http://www.w3.org/1999/xhtml"> 3 Add this line of code to viewmodel

The binding should always be successful:

Yes, it succeeded. You can't forget to activate Ko code.

 

 

The landlord bullied me to read less books and had no culture. I only wrote a simple declarative binding, not to say that Ko could automatically refresh the ui or something. Is it a little boring to write it out? Well, I didn't bully you. It's just that the primary author is involved in Ko, so it's a beginner. What you said should be the function that automatically refreshes the page when the model status changes. I just learned this. Write a hello World for the Ko automatic refresh page. You can refer to the following code.
1 <! Doctype HTML> 2 <HTML xmlns = "http://www.w3.org/1999/xhtml"> 3 Hello World

I didn't understand the code, was it bullied or uncultured by you, because I never saw any Hello world.

The code can read Hello world. Explain the code first.

Ko. observable is a very, very basic concept. What it can do is to change the Monitoring Value and respond to its corresponding changes. Ko. computed, which is used to calculate the value of the monitoring attribute (E is weak, so I simply understand it ). For example, the first monitoring word and the second monitoring word are combined above. Then, let's see if there will be "Hi Ando" shown to us at the end. Yes. However, the poster still does not see hello World. ko. computed can calculate the changes to the monitored values (here, the two monitored values are combined), so without changing the code, if we change the first value on the page to "hello" and the second value to "world", will we see "Hello World" below? Let's try. Decisive success. This is because the first learning note for learning Ko is here. Although the learning content is simple and it takes time to write a blog, it is still improving, isn't it? I also hope that I can continue to learn Ko and write down my blog. If I can meet some friends who can learn Ko together, it is also very good.

I am now listening to the ink painting Dan Qing Phoenix City, sitting in the chair, think of the sentence: Like a king!

 

Learning knockout Hello World

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.