[Web API series tutorial] 3.7-practice: process data (create a UI view)

Source: Internet
Author: User

[Web API series tutorial] 3.7-practice: process data (create a UI view)

In this section, you will start to define HTML for the app and add data binding between the HTML and view model.

Open the Views/Home/Index. cshtml file. Use the following code to replace all the content of the file.

<code class=" hljs xml">@section scripts {  @Scripts.Render("~/bundles/app")}  </code>
BookService Books
  • : Details

The vast majority of div elements here are in the Bootstrap style, which is an important element of the Data Binding attribute. This element links HTML to the view model.

For example:

In this example, the "text" binding causes the p element to display the error attribute value in the view model. The error callback is declared in ko. obserable:

self.error = ko.observable(); 

Whenever a new value is modified to an error, the Knockout will update the text on the <p> element.

The foreach binding tells Knockout to traverse cyclically in the books array. For each entry of the array, Knockout creates a new <li> element. Bind the context referenced by foreach to each item of the array. For example:

 

Here there is a text binding to read the Author attribute of each book.

If you run the application now, it looks like this:

After a page is loaded, the books list is asynchronously loaded. Currently, the "Details" link is not functional yet. We will add this feature for it in the next section.

Related Article

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.