Desktop application programmers simply try rich JavaScript Application

Source: Internet
Author: User

Although I developed web applications for a period of time 10 years ago, I designed a web application development framework based on ASP. NET webforms (Based on. NET 1.1) for my enterprise. However, we have been working on desktop applications, such as smartclient, Silverlight-based Ria, and even now, our company's products are single-host winforms applications with pure clients. Therefore, I should be a thorough desktop application.ProgramMember. I haven't touched anything like JavaScript for a long time.

The recent reasons for interest in JavaScript are as follows:

    • In the past one year, node. js has been very popular. I want to know more about it. In particular, azure (and webmatrix) has enhanced my interest in node. js support;
    • ASP. net mvc has a built-in JavaScript library named knockoutjs of mvvm. I want to know why Microsoft has a special liking for Ko;
    • Windows 8 apps can be developed using JavaScript and HTML5. It can be seen that JavaScript will be useful even for desktop applications in the future;
    • Microsoft launched typescript, as well as the unofficial Microsoft Script # And coffeescript which have been paid close attention to, all of which indicate that people want to use JavaScript to develop large and more rich applications in a simpler way.

The following is a simple attempt:

    • The company's official website is built with PHP, which is not very familiar with PHP and does not want to adjust the original website framework;
    • Company blog built on WordPress
    • You need to automatically display the latest blog information on the official website.ArticleList

Since I have already started learning knockout, I decided to implement the above scenario based on Ko yesterday. This is a practical attempt on Ko. The procedure is as follows:

    1. Install the feed JSON plug-in WordPress to expose the JSON interface.
    2. Create an HTML file and deploy it to the website root directory
    3. Create a topic block on the official website (custom HTML is supported). Insert the IFRAME element to point to the preceding HTML file. I tried to implement it directly in HTML before.CodeBut the jquery version will conflict, so use IFRAME instead.

The HTML file of this simple application is as follows:

<Body> <div> <Div data-bind = "Foreach: blogs" > <P> <a data-bind = "ATTR: {href: $ data. permalink, Title: $ data. Title }" Target = "_ Blank" > <Span data-bind = "Text: $ data. Date" > </Span>: <span data-bind = "Text: $ data. Title" > </Span> </a> </P> </div> <a href ="Blog" Title = "More" Target = "_ Blank" > More </a> </div> <SCRIPT type = 'Text/JavaScript' > Function blog (data ){ This . Title = Ko. observable (data. Title ); This . Permalink = Ko. observable (data. permalink ); This . Date = Ko. observable (data. Date. substr (0, 10);} function blogviewmodel () {var self = This ; Self. Blogs = Ko. observablearray ([]); $. getjson ( "/Blog /? Feed = JSON" , Function (alldata) {var mappedblogs = $. Map (alldata, function (item ){ Return   New Blog (item)}); self. Blogs (mappedblogs) ;});} KO. applybindings ( New Blogviewmodel (); </SCRIPT> </body>

The preceding HTML file is divided into two parts. The first part is the HTML used to display the interface, and the second part is the definition of the object and the JavaScript code for getting data to execute the binding.

In the first part, I am very familiar with the binding mechanism using the mvvm idea. This is not much different from XAML.

In the second part, we first use jquery to obtain JSON data and convert it to a bound JavaScript Object (this is a simple surprise to me). You can bind it to Ko. and then provide an array attribute that can be bound to the interface (that is, the blogs attribute) in the viewmodel object ).

Although the above functions are simple, I think I have touched the implementation path of the so-called rich JavaScript Application or the scale JavaScript Application called by Microsoft. That is:

    • Use a framework like jquery to simplify Dom operations
    • Use a library or framework such as knockoutjs or angularjs to simplify data presentation and behavior Processing
    • Use coffeescript or typescript to simplify JavaScript writing
    • Develop client-only applications that can run across browsers, and have the ability to interact with the server (generally based on restful). Such applications are highly interactive and can complete complex data operations.

Here is a reference article worth reading:

Rich JavaScript applications-the seven frameworks (Throne of JS, 2012)
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.