[Web API series tutorial] 3.8-practice: process data (display entry details)

Source: Internet
Author: User

[Web API series tutorial] 3.8-practice: process data (display entry details)

In this section, you will add the function to view details of each book. In app. js, add the following code to the view model:

self.detail = ko.observable();self.getBookDetail = function (item) {    ajaxHelper(booksUri + item.Id, 'GET').done(function (data) {        self.detail(data);    });}

In Views/Home/Index. cshtml, add a data binding element to the Details link:

 
  • : Details

It binds the <a> element to a click event that calls the getBookDetail function in the view model.

In the same file, replace the following code:

<code class=" hljs xml">    <!--{cke_protected}{C}%3C!%2D%2D%20TODO%3A%20Book%20details%20%2D%2D%3E--></code>

To:

<code class=" hljs xml"><!--{cke_protected}{C}%3C!%2D%2D%20ko%20if%3Adetail()%20%2D%2D%3E-->      </code>
Detail
Author  
Title  
Year  
Genre  
Price  

This Code creates a table bound to the details attributes in the view model.

"


  

Now, if you run this application and click a "Detail" link, the app will display the details of the book.

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.