1

我想构建一个带有 StackMob 后端的 PhoneGap HTML5 应用程序。似乎缺少有关该主题的书籍、视频和教程。

具体来说,如何在不使用 Require.js 和 Backbone.js 的情况下构建 Phonegap + StackMob 应用程序?

4

2 回答 2

1

我认为 stackmob 开发者网站:https ://developer.stackmob.com/是最好的资源。

于 2013-07-26T15:16:58.540 回答
1

使用带有 StackMob 的 phoneGap 独立于使用 Backbone.js 和 Require.js。StackMob SDK 是使用 Backbone.js 构建的,用于管理模型和集合。

因此,如果您想构建一个没有 Backbone.js 的应用程序,您可以对 StackMob 进行裸 AJAX 调用。这是一个展示如何的JSFiddle。

http://jsfiddle.net/ericktai/mr925/

   /*
We want to prepare the Request headers we're going to send to StackMob.  It should look like:

{
  'Accept': application/vnd.stackmob+json; version=0',
  'X-StackMob-API-Key-dc0e228a-ccd3-4799-acd5-819f6c074ace': 1,
  'Range': 'objects=0-9'  //this is optional, but I did it here to show pagination and extra header fields
}

You can actually have the public key in the header as:

'X-StackMob-API-Key': dc0e228a-ccd3-4799-acd5-819f6c074ace

OR

'X-StackMob-API-Key-dc0e228a-ccd3-4799-acd5-819f6c074ace': 1

The first is our original format.  The reason why I chose the latter is because of this specific example.  I'm making cross domain requests jsfiddle.net to api.stackmob.com, which the browser doesn't allow UNLESS we use CORS (cross origin resource sharing).  StackMob servers support CORS, but it needs the latter header format to do so.  (it was introduced later).  iOS and Android SDKs use the first format.

Node.js should be able to use the first format because it doesn't restrict cross domain calls.

The "1" value in the latter format is arbitrary.  IE just doesn't allow the value of a header to be empty, so we filled it with "1".
*/

var publicKeyHeader = 'X-StackMob-API-Key-dc0e228a-ccd3-4799-acd5-819f6c074ace';
var requestHeaders = {};
requestHeaders['Accept'] = 'application/vnd.stackmob+json; version=0';
requestHeaders[publicKeyHeader] = 1;
requestHeaders['Range'] = 'objects=0-9'; //set pagination to first 10

$.ajax({
    url: 'https://api.stackmob.com/item',
    headers: requestHeaders, //set the headers
    type: 'GET',
    success: function(data, textStatus, xhr) {
        console.debug(data);
    },
    error: function(xhr, textStatus, error) {
        console.debug(error);
    }
});

关于 phoneGap,您需要查看以下文档。

https://developer.stackmob.com/js-sdk/using-the-js-sdk-with-phonegap-guide

我已经成功使用 Adob​​e phoneGap 构建。

顺便说一句-我是 StackMob 的平台传播者

于 2013-08-13T22:50:50.680 回答