Notes for using knockout

Source: Internet
Author: User

1. Value Change trigger time

After the view is changed, the focus leaves the current Dom element, and the value of view-model changes. You can setValueupdate: "afterkeydown"To change the view value, the view-model value changes immediately (similar to the onkeyup event ).

After the view-model is changed, the value of the view changes immediately.

2. Pay attention to the transfer of reference and Value

Value transfer, the most common is that your model type is string and number, so you changed the value of the model, the view-model remains unchanged.

For reference transfer, the most common is the array type. Your model type array data, shift (), your view-model changes, and your view changes.

3. Select element Click Event

Select element. You have bound a click event, which is actually a double-click event. Its click event is change.

4. foreach binding

1. The required array format is [{key: value1}, {key: value2}], which may be different from the array format saved in your database. Therefore, you need a conversion function.

2. If you want to bind the array format [value1, value2, value3], use $ data. However, this will only display data. If you modify the data in the view, the view-model will not be affected because this is a value transfer.

Iii. $ Parent concept. The current object is in the set and is often used for remove. $ Root refers to set a packet Set B packet set C, $ root of set C is set a, and $ parent of set C is set B.

5. bind

Foreach is bound to an array, while with is bound to an object.

6. Custom binding

Now you can bind the value and text fields to the knockout, and write the yourname binding.

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.