SlideShare a Scribd company logo
1 of 4
Download to read offline
Sample Appcelerator Alloy Mobile Project for Howard U SCS
Cross-Platform Mobile App Dev Class
Project is based off of the default 2 Tab template available in Titanium Studio.q
Project is a sample demonstrating the use of a restApi sync adapter along with Model/Collectionq
Databinding to a TableView
The project is connected to a Kinvey Datasource back end. See Kinvey to setup a free account toq
fully utilize this application
This code should run successfully on IOS and Android using the Appcelerator 3.5.0 SDKq
Getting Started
Please setup your constants by modifying the file kinveyConstants.js in the applib directory of
your project
Modify the code below to use your values from the kinvey console
exports.constants = {
url : 'https://baas.kinvey.com/appdata/kid_-XXXXXXX/Devices',
basicAuthValue : 'Basic a2lkXy1KZWlXXXXXXXOTliY2RhMDE0YzQ5ZDBmNjY2OA=='
};
Devices Model js file
This file is where the application is a bit different from the default model file.
The default file starts off like this
exports.definition = {
config: {
adapter: {
type: "properties",
collection_name: "Foo"
}
},
extendModel: function(Model) {
_.extend(Model.prototype, {
// extended functions and properties go here
});
return Model;
},
extendCollection: function(Collection) {
_.extend(Collection.prototype, {
// extended functions and properties go here
});
return Collection;
}
};
Lets start to explain the changes we have made...first off at the top, we are using javascript require
to include the kinveyConstants.js discussed above. This will provide access to the constants in the
model.
// I have saved constants in an external file that is included here using the
// javascript requires functionality
//
// Best Practices for Alloy and discussion on requires:
//
http://docs.appcelerator.com/titanium/3.0/#!/guide/Alloy_Best_Practices_and_Recomme
ndations
//
var KINVEY_CONST = require("kinveyConstants").constants;
Set the Sync Adapter
Next we need to set the model to use the appropriate sync adapter. I have included a default sync
adapter that we have used on some projects that you are welcome to use.
You need to make sure the sync adapter that you use in included in the lib/alloy/sync directory
in the project. In this case, the file name in restapi.js
config : {
adapter : {
// Specifiy the sync adapter to use for this model
// and collection
type : "restapi",
// collection name property, not really needed when using
// the REST API sync adapter
collection_name : "Devices"
}
},
Extend the Model to Specify URL
For the sync adapter to work with a rest API, it needs a base url. We provide a function that will
return the base url for the model and collection. We have the value for the url in the
kinveyConstants.js file that we loaded up in the top of the models file... this is how we use the
object KINVEY_CONST we loaded up
_.extend(Model.prototype, {
// extended functions and properties go here
url : function() {
return KINVEY_CONST.url;
}
});
This code is extending the default object to include/override the existing function with a new
function to provide the base url. Additional infomation on baseUrl can be found in the BackboneJS
Documentation
Extend the Model to Specify Authorization Header
For this example, we are authenticating our API calls with Basic Auth using the headers; This is not
the recommended apporoach, but meets the needs of this sample.
BackboneJS allows for specifying the headers before the request is made by setting the beforeSend
property with a function to call before sending the request. We will use that property to call a
function that will set the authentication header.
The code for the function to set the headers can be placed in the controller and would need to be
used everytime you wanted to access a collection, but from a design approach it might be better to
keep the code in the model.
What we have done is extend the model with a function to set the headers on the request. The
function is added here, in the controller code, you will see how it is utilized.
_.extend(Collection.prototype, {
// extended functions and properties go here
/**
* a function for setting the header when requests are made.
*
* @param {Object} xhr
*/
setHeader : function(xhr) {
xhr.setRequestHeader("Authorization", KINVEY_CONST.basicAuthValue);
},
});
Fetching the Data in index.js
In the index controller we can now create a new Devices collection by using the Alloy.instance
function'
var devicesCollection = Alloy.Collections.instance("Devices")
this will get the existing collection or create a new collection based on the information in the
Devices model .js file.
Now that we have a devicesCollection object now lets call the fetch method to get the data
associated with the collection. The data associated with the collection will be returned as model
objects. Remember though that we need to set the header for the authentication by using the
function we added to the collection.
See the BackboneJS Collection.fetch documentation for additonal information of fetch and the
associated options.
devicesCollection.fetch({
beforeSend : devicesCollection.setHeader, // the function from the extended
collection
success : function(collection, response, option) {
// dump the results from the fetch to the console
console.log("Collection Response: " + JSON.stringify(collection, null, 2));
},
error : function(collection, response, option) {
console.log('ERROR ' + collection);
}
});
Binding the the Data in index.xml View
Alloy Data-Binding Documentation
Responding to Events in index.xml View

More Related Content

What's hot

Advanced AngularJS Concepts
Advanced AngularJS ConceptsAdvanced AngularJS Concepts
Advanced AngularJS ConceptsKyle Hodgson
 
Angular elements - embed your angular components EVERYWHERE
Angular elements - embed your angular components EVERYWHEREAngular elements - embed your angular components EVERYWHERE
Angular elements - embed your angular components EVERYWHERENadav Mary
 
Angular2 + New Firebase in Action
Angular2 + New Firebase in ActionAngular2 + New Firebase in Action
Angular2 + New Firebase in ActionRuben Chavarri
 
What is Angular version 4?
What is Angular version 4?What is Angular version 4?
What is Angular version 4?Troy Miles
 
Bootiful Development with Spring Boot and React - GIDS 2019
Bootiful Development with Spring Boot and React - GIDS 2019Bootiful Development with Spring Boot and React - GIDS 2019
Bootiful Development with Spring Boot and React - GIDS 2019Matt Raible
 
Alloy Simple App Demonstration
Alloy Simple App DemonstrationAlloy Simple App Demonstration
Alloy Simple App DemonstrationAaron Saunders
 
Appcelerator Titanium Alloy
Appcelerator Titanium Alloy Appcelerator Titanium Alloy
Appcelerator Titanium Alloy karthi-anubavam
 
Orgchart for Alfresco lightning talk
Orgchart for Alfresco lightning talkOrgchart for Alfresco lightning talk
Orgchart for Alfresco lightning talkITD Systems
 
Building 3D Models with Skycatch & Autodesk Recap API's
Building 3D Models with Skycatch & Autodesk Recap API'sBuilding 3D Models with Skycatch & Autodesk Recap API's
Building 3D Models with Skycatch & Autodesk Recap API'sChristopher Bumgardner
 
Introduction to Angular 2
Introduction to Angular 2Introduction to Angular 2
Introduction to Angular 2Trung Vo Tuan
 
Up & running with ECMAScript6
Up & running with ECMAScript6Up & running with ECMAScript6
Up & running with ECMAScript6Nir Kaufman
 
Building The SpringGraph Flex Component
Building The SpringGraph Flex ComponentBuilding The SpringGraph Flex Component
Building The SpringGraph Flex ComponentGuo Albert
 
Modules in AngularJs
Modules in AngularJsModules in AngularJs
Modules in AngularJsK Arunkumar
 
Creating a Symfony Ecommerce App
Creating a Symfony Ecommerce AppCreating a Symfony Ecommerce App
Creating a Symfony Ecommerce AppMuhammad Azaz Qadir
 
Getting Started with the Angular 2 CLI
Getting Started with the Angular 2 CLIGetting Started with the Angular 2 CLI
Getting Started with the Angular 2 CLIJim Lynch
 
Making share point rock with angular and react
Making share point rock with angular and reactMaking share point rock with angular and react
Making share point rock with angular and reactJoseph Jorden
 
Tales of an open source library
Tales of an open source libraryTales of an open source library
Tales of an open source libraryAdam Klein
 
Say hello world with angular 5
Say hello world with angular 5Say hello world with angular 5
Say hello world with angular 5Abhishek Mallick
 

What's hot (20)

Story ofcorespring infodeck
Story ofcorespring infodeckStory ofcorespring infodeck
Story ofcorespring infodeck
 
Advanced AngularJS Concepts
Advanced AngularJS ConceptsAdvanced AngularJS Concepts
Advanced AngularJS Concepts
 
Angular elements - embed your angular components EVERYWHERE
Angular elements - embed your angular components EVERYWHEREAngular elements - embed your angular components EVERYWHERE
Angular elements - embed your angular components EVERYWHERE
 
Angular2 + New Firebase in Action
Angular2 + New Firebase in ActionAngular2 + New Firebase in Action
Angular2 + New Firebase in Action
 
What is Angular version 4?
What is Angular version 4?What is Angular version 4?
What is Angular version 4?
 
Bootiful Development with Spring Boot and React - GIDS 2019
Bootiful Development with Spring Boot and React - GIDS 2019Bootiful Development with Spring Boot and React - GIDS 2019
Bootiful Development with Spring Boot and React - GIDS 2019
 
Alloy Simple App Demonstration
Alloy Simple App DemonstrationAlloy Simple App Demonstration
Alloy Simple App Demonstration
 
Appcelerator Titanium Alloy
Appcelerator Titanium Alloy Appcelerator Titanium Alloy
Appcelerator Titanium Alloy
 
Orgchart for Alfresco lightning talk
Orgchart for Alfresco lightning talkOrgchart for Alfresco lightning talk
Orgchart for Alfresco lightning talk
 
Building 3D Models with Skycatch & Autodesk Recap API's
Building 3D Models with Skycatch & Autodesk Recap API'sBuilding 3D Models with Skycatch & Autodesk Recap API's
Building 3D Models with Skycatch & Autodesk Recap API's
 
Introduction to Angular 2
Introduction to Angular 2Introduction to Angular 2
Introduction to Angular 2
 
Up & running with ECMAScript6
Up & running with ECMAScript6Up & running with ECMAScript6
Up & running with ECMAScript6
 
Building The SpringGraph Flex Component
Building The SpringGraph Flex ComponentBuilding The SpringGraph Flex Component
Building The SpringGraph Flex Component
 
Modules in AngularJs
Modules in AngularJsModules in AngularJs
Modules in AngularJs
 
Creating a Symfony Ecommerce App
Creating a Symfony Ecommerce AppCreating a Symfony Ecommerce App
Creating a Symfony Ecommerce App
 
Getting Started with the Angular 2 CLI
Getting Started with the Angular 2 CLIGetting Started with the Angular 2 CLI
Getting Started with the Angular 2 CLI
 
Making share point rock with angular and react
Making share point rock with angular and reactMaking share point rock with angular and react
Making share point rock with angular and react
 
Tales of an open source library
Tales of an open source libraryTales of an open source library
Tales of an open source library
 
Say hello world with angular 5
Say hello world with angular 5Say hello world with angular 5
Say hello world with angular 5
 
Testing AngularJS
Testing AngularJSTesting AngularJS
Testing AngularJS
 

Viewers also liked

Son 6 yılda Facebook infografisi
Son 6 yılda Facebook infografisiSon 6 yılda Facebook infografisi
Son 6 yılda Facebook infografisiquisif
 
DC Titanium User Group Meetup: Appcelerator Titanium Alloy jan2013
DC Titanium User Group Meetup: Appcelerator Titanium Alloy jan2013DC Titanium User Group Meetup: Appcelerator Titanium Alloy jan2013
DC Titanium User Group Meetup: Appcelerator Titanium Alloy jan2013Aaron Saunders
 
2016 open day event guide
2016 open day event guide2016 open day event guide
2016 open day event guideTariq Mahmood
 
Presentasi sip kelompok 5
Presentasi sip kelompok 5Presentasi sip kelompok 5
Presentasi sip kelompok 5Ade Frihadi
 

Viewers also liked (6)

João Game
João GameJoão Game
João Game
 
Son 6 yılda Facebook infografisi
Son 6 yılda Facebook infografisiSon 6 yılda Facebook infografisi
Son 6 yılda Facebook infografisi
 
Techos
TechosTechos
Techos
 
DC Titanium User Group Meetup: Appcelerator Titanium Alloy jan2013
DC Titanium User Group Meetup: Appcelerator Titanium Alloy jan2013DC Titanium User Group Meetup: Appcelerator Titanium Alloy jan2013
DC Titanium User Group Meetup: Appcelerator Titanium Alloy jan2013
 
2016 open day event guide
2016 open day event guide2016 open day event guide
2016 open day event guide
 
Presentasi sip kelompok 5
Presentasi sip kelompok 5Presentasi sip kelompok 5
Presentasi sip kelompok 5
 

Similar to Appcelerator Titanium Alloy + Kinvey Collection Databinding - Part One

Appear IQ - Tutorials Backbone.js
Appear IQ - Tutorials Backbone.jsAppear IQ - Tutorials Backbone.js
Appear IQ - Tutorials Backbone.jsAppear
 
How to Implement Micro Frontend Architecture using Angular Framework
How to Implement Micro Frontend Architecture using Angular FrameworkHow to Implement Micro Frontend Architecture using Angular Framework
How to Implement Micro Frontend Architecture using Angular FrameworkRapidValue
 
Spring review_for Semester II of Year 4
Spring review_for Semester II of Year 4Spring review_for Semester II of Year 4
Spring review_for Semester II of Year 4than sare
 
.NET Portfolio
.NET Portfolio.NET Portfolio
.NET Portfoliomwillmer
 
Volley lab btc_bbit
Volley lab btc_bbitVolley lab btc_bbit
Volley lab btc_bbitCarWash1
 
Adding User Management to Node.js
Adding User Management to Node.jsAdding User Management to Node.js
Adding User Management to Node.jsDev_Events
 
SharePoint Saturday Atlanta 2015
SharePoint Saturday Atlanta 2015SharePoint Saturday Atlanta 2015
SharePoint Saturday Atlanta 2015Pushkar Chivate
 
China Science Challenge
China Science ChallengeChina Science Challenge
China Science Challengeremko caprio
 
SgCodeJam24 Workshop
SgCodeJam24 WorkshopSgCodeJam24 Workshop
SgCodeJam24 Workshopremko caprio
 
How to Webpack your Django!
How to Webpack your Django!How to Webpack your Django!
How to Webpack your Django!David Gibbons
 
Introduction to Spring Framework
Introduction to Spring FrameworkIntroduction to Spring Framework
Introduction to Spring FrameworkRajind Ruparathna
 
React Hooks Best Practices in 2022.pptx
React Hooks Best Practices in 2022.pptxReact Hooks Best Practices in 2022.pptx
React Hooks Best Practices in 2022.pptxBOSC Tech Labs
 
Creating web api and consuming- part 1
Creating web api and consuming- part 1Creating web api and consuming- part 1
Creating web api and consuming- part 1Dipendra Shekhawat
 
Django 1.10.3 Getting started
Django 1.10.3 Getting startedDjango 1.10.3 Getting started
Django 1.10.3 Getting startedMoniaJ
 

Similar to Appcelerator Titanium Alloy + Kinvey Collection Databinding - Part One (20)

Appear IQ - Tutorials Backbone.js
Appear IQ - Tutorials Backbone.jsAppear IQ - Tutorials Backbone.js
Appear IQ - Tutorials Backbone.js
 
How to Implement Micro Frontend Architecture using Angular Framework
How to Implement Micro Frontend Architecture using Angular FrameworkHow to Implement Micro Frontend Architecture using Angular Framework
How to Implement Micro Frontend Architecture using Angular Framework
 
Grails Advanced
Grails Advanced Grails Advanced
Grails Advanced
 
Spring review_for Semester II of Year 4
Spring review_for Semester II of Year 4Spring review_for Semester II of Year 4
Spring review_for Semester II of Year 4
 
Actionview
ActionviewActionview
Actionview
 
Rails review
Rails reviewRails review
Rails review
 
.NET Portfolio
.NET Portfolio.NET Portfolio
.NET Portfolio
 
Volley lab btc_bbit
Volley lab btc_bbitVolley lab btc_bbit
Volley lab btc_bbit
 
Adding User Management to Node.js
Adding User Management to Node.jsAdding User Management to Node.js
Adding User Management to Node.js
 
SharePoint Saturday Atlanta 2015
SharePoint Saturday Atlanta 2015SharePoint Saturday Atlanta 2015
SharePoint Saturday Atlanta 2015
 
Express node js
Express node jsExpress node js
Express node js
 
Cognos Software Development Kit
Cognos Software Development KitCognos Software Development Kit
Cognos Software Development Kit
 
China Science Challenge
China Science ChallengeChina Science Challenge
China Science Challenge
 
SgCodeJam24 Workshop
SgCodeJam24 WorkshopSgCodeJam24 Workshop
SgCodeJam24 Workshop
 
How to Webpack your Django!
How to Webpack your Django!How to Webpack your Django!
How to Webpack your Django!
 
Introduction to Spring Framework
Introduction to Spring FrameworkIntroduction to Spring Framework
Introduction to Spring Framework
 
React Hooks Best Practices in 2022.pptx
React Hooks Best Practices in 2022.pptxReact Hooks Best Practices in 2022.pptx
React Hooks Best Practices in 2022.pptx
 
Backbone.js
Backbone.jsBackbone.js
Backbone.js
 
Creating web api and consuming- part 1
Creating web api and consuming- part 1Creating web api and consuming- part 1
Creating web api and consuming- part 1
 
Django 1.10.3 Getting started
Django 1.10.3 Getting startedDjango 1.10.3 Getting started
Django 1.10.3 Getting started
 

More from Aaron Saunders

Mobile Application Workshop - So You Want To Build a Mobile App?
Mobile Application Workshop - So You Want To Build a Mobile App?Mobile Application Workshop - So You Want To Build a Mobile App?
Mobile Application Workshop - So You Want To Build a Mobile App?Aaron Saunders
 
Getting Started with Appcelerator Alloy - Cross Platform Mobile Development -...
Getting Started with Appcelerator Alloy - Cross Platform Mobile Development -...Getting Started with Appcelerator Alloy - Cross Platform Mobile Development -...
Getting Started with Appcelerator Alloy - Cross Platform Mobile Development -...Aaron Saunders
 
Identify & Unlock Your Mobile Strategy
Identify & Unlock Your Mobile StrategyIdentify & Unlock Your Mobile Strategy
Identify & Unlock Your Mobile StrategyAaron Saunders
 
SubAid User Guide - Overview
SubAid User Guide - OverviewSubAid User Guide - Overview
SubAid User Guide - OverviewAaron Saunders
 
DC Health Link New Mobile App 1.0 Brings Health Insurance Resources to Consum...
DC Health Link New Mobile App 1.0 Brings Health Insurance Resources to Consum...DC Health Link New Mobile App 1.0 Brings Health Insurance Resources to Consum...
DC Health Link New Mobile App 1.0 Brings Health Insurance Resources to Consum...Aaron Saunders
 
Amsterdam Titanium User Group - Cloud Services for Apps Nov 2013
Amsterdam Titanium User Group - Cloud Services for Apps Nov 2013Amsterdam Titanium User Group - Cloud Services for Apps Nov 2013
Amsterdam Titanium User Group - Cloud Services for Apps Nov 2013Aaron Saunders
 
Simple Unit Testing in Appcelerator Titanium Alloy
Simple Unit Testing in Appcelerator Titanium AlloySimple Unit Testing in Appcelerator Titanium Alloy
Simple Unit Testing in Appcelerator Titanium AlloyAaron Saunders
 
modeveast 2012 Appcelerator Alloy & Cloud Services Presentation
modeveast 2012 Appcelerator Alloy & Cloud Services Presentationmodeveast 2012 Appcelerator Alloy & Cloud Services Presentation
modeveast 2012 Appcelerator Alloy & Cloud Services PresentationAaron Saunders
 
Introduction to Module Development with Appcelerator Titanium
Introduction to Module Development with Appcelerator TitaniumIntroduction to Module Development with Appcelerator Titanium
Introduction to Module Development with Appcelerator TitaniumAaron Saunders
 
Clearly Innovative Inc Capabilities
Clearly Innovative Inc CapabilitiesClearly Innovative Inc Capabilities
Clearly Innovative Inc CapabilitiesAaron Saunders
 
PaaS + Appcelerator = WIN
PaaS + Appcelerator = WINPaaS + Appcelerator = WIN
PaaS + Appcelerator = WINAaron Saunders
 
StackMob & Appcelerator Module Part One
StackMob & Appcelerator Module Part OneStackMob & Appcelerator Module Part One
StackMob & Appcelerator Module Part OneAaron Saunders
 
Modeveast Appcelerator Presentation
Modeveast Appcelerator PresentationModeveast Appcelerator Presentation
Modeveast Appcelerator PresentationAaron Saunders
 

More from Aaron Saunders (13)

Mobile Application Workshop - So You Want To Build a Mobile App?
Mobile Application Workshop - So You Want To Build a Mobile App?Mobile Application Workshop - So You Want To Build a Mobile App?
Mobile Application Workshop - So You Want To Build a Mobile App?
 
Getting Started with Appcelerator Alloy - Cross Platform Mobile Development -...
Getting Started with Appcelerator Alloy - Cross Platform Mobile Development -...Getting Started with Appcelerator Alloy - Cross Platform Mobile Development -...
Getting Started with Appcelerator Alloy - Cross Platform Mobile Development -...
 
Identify & Unlock Your Mobile Strategy
Identify & Unlock Your Mobile StrategyIdentify & Unlock Your Mobile Strategy
Identify & Unlock Your Mobile Strategy
 
SubAid User Guide - Overview
SubAid User Guide - OverviewSubAid User Guide - Overview
SubAid User Guide - Overview
 
DC Health Link New Mobile App 1.0 Brings Health Insurance Resources to Consum...
DC Health Link New Mobile App 1.0 Brings Health Insurance Resources to Consum...DC Health Link New Mobile App 1.0 Brings Health Insurance Resources to Consum...
DC Health Link New Mobile App 1.0 Brings Health Insurance Resources to Consum...
 
Amsterdam Titanium User Group - Cloud Services for Apps Nov 2013
Amsterdam Titanium User Group - Cloud Services for Apps Nov 2013Amsterdam Titanium User Group - Cloud Services for Apps Nov 2013
Amsterdam Titanium User Group - Cloud Services for Apps Nov 2013
 
Simple Unit Testing in Appcelerator Titanium Alloy
Simple Unit Testing in Appcelerator Titanium AlloySimple Unit Testing in Appcelerator Titanium Alloy
Simple Unit Testing in Appcelerator Titanium Alloy
 
modeveast 2012 Appcelerator Alloy & Cloud Services Presentation
modeveast 2012 Appcelerator Alloy & Cloud Services Presentationmodeveast 2012 Appcelerator Alloy & Cloud Services Presentation
modeveast 2012 Appcelerator Alloy & Cloud Services Presentation
 
Introduction to Module Development with Appcelerator Titanium
Introduction to Module Development with Appcelerator TitaniumIntroduction to Module Development with Appcelerator Titanium
Introduction to Module Development with Appcelerator Titanium
 
Clearly Innovative Inc Capabilities
Clearly Innovative Inc CapabilitiesClearly Innovative Inc Capabilities
Clearly Innovative Inc Capabilities
 
PaaS + Appcelerator = WIN
PaaS + Appcelerator = WINPaaS + Appcelerator = WIN
PaaS + Appcelerator = WIN
 
StackMob & Appcelerator Module Part One
StackMob & Appcelerator Module Part OneStackMob & Appcelerator Module Part One
StackMob & Appcelerator Module Part One
 
Modeveast Appcelerator Presentation
Modeveast Appcelerator PresentationModeveast Appcelerator Presentation
Modeveast Appcelerator Presentation
 

Recently uploaded

Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobeapidays
 
Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Zilliz
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businesspanagenda
 
Platformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityPlatformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityWSO2
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Orbitshub
 
Six Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal OntologySix Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal Ontologyjohnbeverley2021
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingEdi Saputra
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...apidays
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...Zilliz
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDropbox
 
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUKSpring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUKJago de Vreede
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...apidays
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native ApplicationsWSO2
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxRustici Software
 
WSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Victor Rentea
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherRemote DBA Services
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...apidays
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...DianaGray10
 

Recently uploaded (20)

Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Platformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityPlatformless Horizons for Digital Adaptability
Platformless Horizons for Digital Adaptability
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
 
Six Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal OntologySix Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal Ontology
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUKSpring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
WSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering Developers
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 

Appcelerator Titanium Alloy + Kinvey Collection Databinding - Part One

  • 1. Sample Appcelerator Alloy Mobile Project for Howard U SCS Cross-Platform Mobile App Dev Class Project is based off of the default 2 Tab template available in Titanium Studio.q Project is a sample demonstrating the use of a restApi sync adapter along with Model/Collectionq Databinding to a TableView The project is connected to a Kinvey Datasource back end. See Kinvey to setup a free account toq fully utilize this application This code should run successfully on IOS and Android using the Appcelerator 3.5.0 SDKq Getting Started Please setup your constants by modifying the file kinveyConstants.js in the applib directory of your project Modify the code below to use your values from the kinvey console exports.constants = { url : 'https://baas.kinvey.com/appdata/kid_-XXXXXXX/Devices', basicAuthValue : 'Basic a2lkXy1KZWlXXXXXXXOTliY2RhMDE0YzQ5ZDBmNjY2OA==' }; Devices Model js file This file is where the application is a bit different from the default model file. The default file starts off like this exports.definition = { config: { adapter: { type: "properties", collection_name: "Foo" } }, extendModel: function(Model) { _.extend(Model.prototype, { // extended functions and properties go here }); return Model; }, extendCollection: function(Collection) { _.extend(Collection.prototype, { // extended functions and properties go here });
  • 2. return Collection; } }; Lets start to explain the changes we have made...first off at the top, we are using javascript require to include the kinveyConstants.js discussed above. This will provide access to the constants in the model. // I have saved constants in an external file that is included here using the // javascript requires functionality // // Best Practices for Alloy and discussion on requires: // http://docs.appcelerator.com/titanium/3.0/#!/guide/Alloy_Best_Practices_and_Recomme ndations // var KINVEY_CONST = require("kinveyConstants").constants; Set the Sync Adapter Next we need to set the model to use the appropriate sync adapter. I have included a default sync adapter that we have used on some projects that you are welcome to use. You need to make sure the sync adapter that you use in included in the lib/alloy/sync directory in the project. In this case, the file name in restapi.js config : { adapter : { // Specifiy the sync adapter to use for this model // and collection type : "restapi", // collection name property, not really needed when using // the REST API sync adapter collection_name : "Devices" } }, Extend the Model to Specify URL For the sync adapter to work with a rest API, it needs a base url. We provide a function that will return the base url for the model and collection. We have the value for the url in the kinveyConstants.js file that we loaded up in the top of the models file... this is how we use the object KINVEY_CONST we loaded up _.extend(Model.prototype, { // extended functions and properties go here url : function() {
  • 3. return KINVEY_CONST.url; } }); This code is extending the default object to include/override the existing function with a new function to provide the base url. Additional infomation on baseUrl can be found in the BackboneJS Documentation Extend the Model to Specify Authorization Header For this example, we are authenticating our API calls with Basic Auth using the headers; This is not the recommended apporoach, but meets the needs of this sample. BackboneJS allows for specifying the headers before the request is made by setting the beforeSend property with a function to call before sending the request. We will use that property to call a function that will set the authentication header. The code for the function to set the headers can be placed in the controller and would need to be used everytime you wanted to access a collection, but from a design approach it might be better to keep the code in the model. What we have done is extend the model with a function to set the headers on the request. The function is added here, in the controller code, you will see how it is utilized. _.extend(Collection.prototype, { // extended functions and properties go here /** * a function for setting the header when requests are made. * * @param {Object} xhr */ setHeader : function(xhr) { xhr.setRequestHeader("Authorization", KINVEY_CONST.basicAuthValue); }, }); Fetching the Data in index.js In the index controller we can now create a new Devices collection by using the Alloy.instance function' var devicesCollection = Alloy.Collections.instance("Devices") this will get the existing collection or create a new collection based on the information in the Devices model .js file. Now that we have a devicesCollection object now lets call the fetch method to get the data associated with the collection. The data associated with the collection will be returned as model
  • 4. objects. Remember though that we need to set the header for the authentication by using the function we added to the collection. See the BackboneJS Collection.fetch documentation for additonal information of fetch and the associated options. devicesCollection.fetch({ beforeSend : devicesCollection.setHeader, // the function from the extended collection success : function(collection, response, option) { // dump the results from the fetch to the console console.log("Collection Response: " + JSON.stringify(collection, null, 2)); }, error : function(collection, response, option) { console.log('ERROR ' + collection); } }); Binding the the Data in index.xml View Alloy Data-Binding Documentation Responding to Events in index.xml View