Nodejs + jquery Mobile build a simple Mobile web (client)

Source: Internet
Author: User

The previous section demonstrates how to use nodejs and jqm to build a simple server that supports CRUD operations on applications (see node. js + jquery Mobile to build a simple Mobile web (server )), the server uses nodejs technology and the mongodb database and the lightweight web development framework expressJS. The routes use the restful style, so you can also use restify for development. Client implementation is mainly implemented through ajax calls. use the jade template engine. the client mainly contains two files: layout. jade and index. jade 1. layout. the jade layout file contains the js and css file copy Code required by the application !!! 5 html head title = 'nodejsjqm 'meta (name = 'viewport', content = 'width = device-width, initial-scale = 1 ') meta (name = 'Apple-mobile-web-app-capable', content = 'yes ') meta (name = 'Apple-mobile-web-app-status-bar-style', content = 'black') link (rel = 'stylesheet ', href = 'HTTP: // code.jquery.com/mobile/1.4.2/jquery.mobile-1.4.2.min.css') script (src = 'HTTP: // code.jquery.com/jquery-1.9.1.min.js') script (src = 'HTTP: // code. j Query.com/mobile/1.4.2/jquery.mobile-1.4.2.min.js') body! = Body copy Code 2. index. jade main interface file, the application uses multi-page design. copy the code div # index (data-role = 'page') div (data-role = 'header', data-theme = 'B') h1 NodeJs and Jqm. ui-btn-right (href = '# add', data-icon = 'gal') add div (data-role = 'content ') ul (data-role = 'listview ', data-inset = 'true', id = 'fruitslist')-for (var index = 0; index <fruits. length; index ++) {li a (href = '# fruitview', id = fruits [index]. _ id) img(src+'1.png ') h3 = fruits [index]. title p = fruits [index]. content-} div (data-role = 'footer ', data-position = 'fixed') div (data-role = 'navbar', data-theme =' B ') ul li a (href = '# Index', data-theme =' B ') Home li a (href =' # ', data-theme =' B ') blog li a (href = '#', data-theme = 'B') Email copy code B. view page, used to view the specified object copy code div # fruitview (data-role = 'page') div (data-role = 'head', data-theme = 'B ') a (data-rel = 'back', data-icon = 'back', data-derection = 'reverse') back h1 fruit view div (data-role = 'content ') div (data-role = 'filedin in') label (for = 'ftitle') Title: h1 # ftitle div (data-role = 'filedin in ') label (for = 'fdesc') Desc: p # fdesc div. ui-bar (data-role = 'footer ', data-theme =' B ', data-position = 'fixed') div (data-role = 'controlgroup ', data-type = 'horizontal ') a (href =' # editfruit ', data-icon = 'gear', data-transition = 'flip ') edit a (href = '# confirmDialog', data-icon = 'delete', data-rel = 'Dialog ') delete copy code c. add new object page copy code div # add (data-role = 'page') div (data-role = 'header', data-theme = 'B ') a (data-rel = 'back', data-icon = 'back', data-derection = 'reverse') back h1 Add fruit a (href = '# add ', data-icon = 'pload') Add div (data-role = 'content') div (data-role = 'filedcontainer') label (for = 'fruit-title ') title input (type = 'text', value = '', id = 'fruit-title', name = 'fruit-title') div (data-role = 'filedin in ') label (for = 'fruit-content') content input (type = 'text', value = '', id = 'fruit-content', name = 'fruit-content ') div (data-role = 'footer ', data-position = 'fixed', data-theme =' B ') a # save-btn (href = '#', data-icon = 'check') Save copy code d. request data through ajax, listen to the beforepageshow event on the page, and process data initialization when the specified page is loaded. For details about the beforepageshow event, refer to the jqm documentation script var mdstore = {}; $ (function () {$ ("# fruitsList "). delegate ('A', 'click', function (e) {mdstore. selectedid = this. id;}); $ ("# index "). bind ('pagebeforeshow ', function (e, ui) {$. get ('fruits/list', function (data) {$ ("# fruitsList "). empty (); for (var index = 0; index <data. length; index ++) {$ ("# fruitsList "). append ('<li> <a href = "# fruitview", id = "' + data [index]. _ id + '">

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.