Use scriptsharp to write knockout. JS Code

Source: Internet
Author: User
Tags jquery library

Knockout. js helps you build the UI in Model-View-viewmodel (mvvm) mode.

This article provides the implementation of scriptsharp based on the example provided by http://learn.knockoutjs.com.

For more information about scriptsharp Quick Start, see: http://www.cnblogs.com/laojia/archive/2011/09/29/2195611.html.

In this example, the scriptsharp Project template is jquery library. After the project is created, you must manually Add a reference to script. Knockout. dll located in the scriptsharp installation folder.

Directly paste the Code:

Page. CS

using System;using System.Runtime.CompilerServices;using jQueryApi;using KnockoutApi;using ScriptSharpKnockout.KnockoutTutorial;namespace ScriptSharpKnockout{    [GlobalMethods]    internal static class Page    {        static Page()        {            jQuery.OnDocumentReady(delegate { Knockout.ApplyBindings(new ViewModel()); });        }    }}

 

Viewmodel. CS

 

Using knockoutapi; namespace scriptsharpknockout. knockouttutorial {public class viewmodel {public observable <string> firstname = knockout. observable <string> ("first name"); Public observable <string> lastname = knockout. observable <string> ("last name"); Public dependentobservable <string> fullname; Public viewmodel () {fullname = knockout. dependentobservable <string> (delegate {return "Hello:" + firstname. getvalue () + "" + lastname. getvalue () ;}) ;}public void updatevalue () {This. lastname. setvalue (this. lastname. getvalue (). touppercase ());}}}

 

Index.htm

 

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

Attaches a project package for download test: http://files.cnblogs.com/laojia/ScriptSharpKnockout.zip

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.