Mobile services batch submit data

Source: Internet
Author: User

Mobile ServicesFor more information about batch data submission, see inserting multiple items at once in azure mobile services. It has already been described clearly, but because it is in English, and there are no examples of Android in some cases, we will take Android development as an example below.

FirstIn the Mobile Services ProjectCreate the alltodoitems and todoitem tables, and clickAlltodoitems, click the script tag to replace the content as follows:

Function insert (item, user, request) {var table = tables. gettable ('todoitem'); populatetable (table, request, item. todos);} function populatetable (table, request, films) {var Index = 0; films. foreach (changereleasedate); var insertnext = function () {If (index> = films. length) {request. respond (201, {ID: 1, status: 'table populated successfully '});} else {var toinsert = films [Index]; table. insert (toinsert, {success: function () {index ++; If (index % 20) = 0) {console. log ('inserted% D items ', index) ;}insertnext () ;}}};}; insertnext () ;}function changereleasedate (OBJ) {var releasedate = obj. releasedate; If (typeof releasedate = 'string') {releasedate = new date (releasedate); obj. releasedate = releasedate ;}}

This completes the work on the server.

Create two classes on the client as follows:

Package COM. example. ecodriveiot;/*** represents an item in a todo list */public class todoitem {/*** item text */@ COM. google. gson. annotations. serializedname ("text") Private string mtext;/*** item ID */@ COM. google. gson. annotations. serializedname ("ID") Private string mid;/*** indicates if the item is completed */@ COM. google. gson. annotations. serializedname ("complete") Private Boolean mcomplete;/*** todoitem constructor */Public todoitem () {}@ overridepublic string tostring () {return gettext ();} /*** initializes a new todoitem *** @ Param text * the item text * @ Param ID * the item ID */Public todoitem (string text, string ID) {This. settext (text); this. setid (ID);}/*** returns the item text */Public String gettext () {return mtext ;} /*** sets the item text ** @ Param text * text to set */public final void settext (string text) {mtext = text ;} /*** returns the item ID */Public String GETID () {return mid ;} /*** sets the item ID ** @ Param ID * ID to set */public final void setid (string ID) {mid = ID ;} /*** indicates if the item is marked as completed */Public Boolean iscomplete () {return mcomplete ;} /*** marks the item as completed or incompleted */Public void setcomplete (Boolean complete) {mcomplete = complete;} @ overridepublic Boolean equals (Object O) {return o instanceof todoitem & (todoitem) O ). mid = mid ;}}

 
Package COM. example. ecodriveiot; public class alltodoitems {@ COM. google. gson. annotations. serializedname ("ID") Public String ID; Public String status; Public todoitem [] Todos ;}

The code for batch submission is as follows:

Todoitem item = new todoitem (); item. settext ("test"); item. setcomplete (false); todoitem [] items = new todoitem [2]; items [0] = item; items [1] = item; // Insert the new item/* mtodotable. insert (item, new tableoperationcallback <todoitem> () {public void oncompleted (todoitem entity, exception, servicefilterresponse response) {If (exception = NULL) {If (! Entity. iscomplete () {madapter. add (entity) ;}}else {createandshowdialog (exception, "error") ;}}); */alltodoitems = new alltodoitems (); alltodoitems. todos = items; mclient. gettable (alltodoitems. class ). insert (alltodoitems, new tableoperationcallback <alltodoitems> () {public void oncompleted (alltodoitems entity, exception, servicefilterresponse response) {If (exception = NULL) {log. I ("debug", "status:" + entity. status) ;}else {createandshowdialog (exception, "error ");}}});

The above code is actually modified based on the SDK demo. You can add the mclient initialization. The development of other clients is similar. You can view the original English text.

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.