Load local JSON data using Sencha touch

Source: Internet
Author: User

This example does not use the Sencha MVC pattern. Just a simple read loading local JSON data sample.

The document structure is as follows:


The App.js code is as follows:

Ext.require ([' Ext.form.Panel ', ' Ext.data.Store ', ' Ext.data.reader.Json ', ' Ext.dataview . DataView ']); Ext.application ({name: ' MyApp ', Icon: ' Images/icon.png ', Glossonicon:false,phonestarupscreen: ' Images/starup.png ', Tabletstartupscreen: ' Images/tablet.png ', launch:function () {ext.define (' User ', {extend: ' Ext.data.Model ', config:{ Fields:[{name: ' id ', type: ' String '},{name: ' name ', type: ' String '},{name: ' img ', type: ' String '},{name: ' Age ', type: ' String '},{name: ' url ', type: ' String '},{name: ' email ', type: ' String '},{name: ' Info ', type: ' String '}]}, Var userstore= Ext.create (' Ext.data.Store ', {model: ' User ', Autoload:true,proxy:{type: ' ajax ', url: ' Userinfo.json ', Reader:{type: ' JSON ', Rootproperty: ' Users '}}), var usertemplate = new Ext.xtemplate (' <tpl for= '. > ', ' <div class= ' user_img ">] No.:{id}<br/> name:{name}< Br/> Age:{age}<br/> Home:{url}<br/> Mail:{email}<br/> personal information:{info}</div> ', ' </tpl> '); var Dataview=exT.create (' Ext.dataview ', {store:userstore,itemtpl:usertemplate,listeners:{itemtap:function (OK, index, target, reco    Rd, E, eopts) {alert (Record.get ("name")); }    }}); Ext.Viewport.add (DataView);}});

The index.html file is as follows:

<! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" >

The Userinfo.json file is as follows:

{"Success": True, "users": [{"id": "1", "name": "Zhang San", "img": "Images/user.jpg", "Age": "All", "url": "Http://zahngsan.com", "Email": "[email protected]", "info": "A Good Boy"},{"id": "2", "Name": "John Doe", "img": "Images/user.jpg", "Age": "All", "url": " Http://lisi.com "," email ":" [email protected] "," info ":" A Good Boy "},{" id ":" 3 "," Name ":" Harry "," img ":" Images/user.jpg "," Age ":", "url": "Http://henghui.com", "E-mail": "[email protected]", "info": "A Good Boy"},{"id": "4", "Name": "Zhao Liu", "IMG" : "Images/user.jpg", "Age": "All", "url": "http://henghui.com", "email": "[email protected]", "info": "A Good Boy"},{"id": " 5 "," Name ":" Money Seven "," img ":" Images/user.jpg "," Age ":" All "," url ":" http://henghui.com "," email ":" [email protected] "," info " : "A good Boy"}]}
Then configure the default homepage in Web. XML to index.html.

Open index.html directly or use the server to access it.

Shown below:




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.