0

iPad用のjavascriptを使用して、チタンでモバイルアプリを開発しています。クライアントのデータは、REST ベースのサービスから要求されます。結果のjsonは、現在私が維持しているさまざまなタイプのステータスIDを提供し、それらをクライアント側の配列にマッピングして、ファイルに多くのゴミを作成しているフロントエンドに表示します。これらの配列を別のjsファイルで列挙型にしてからそれらを必要とすることで、これらの配列を個別に維持することを考えていました..同じためにどのようなアプローチをとるべきですか?

例: json が ID を 0 として送信する場合、クライアント側のファイルで var status = ['Approved-Prodirectional', 'Submitted to Partner', 'Full Receipt'] のような配列を維持し、承認済みの調達可能をステータスとして表示します。

4

1 に答える 1

1

このデータが残りの API によって提供されるソリューションをお勧めします。これが不可能な場合は、すべてのリクエスト ロジックを含む別の JS ファイルを作成する必要があります (おそらく RequestProvider と呼ばれます)。

そこでは、すべての要求呼び出しを行い、応答を準備できます。「コントローラー」では、単に を呼び出しますRequestProvider.doRequest(params, callbackSuccess, callbackError)

function RequestProvider(){}

RequestProvider.prototype.doRequest = function(params, success, error, scope) {
 var client = Ti.Network.createHTTPClient({
     // function called when the response data is available
     onload : function(e) {
         Ti.API.info("Received text: " + this.responseText);
         // prepare & modify answer
         var answer = JSON.parse(this.responseText);
         //modify array
         var modifiedAnswer = // replace parts in original answer;
         success.call(scope || this, modifiedAnswer);
     },
     // function called when an error occurs, including a timeout
     onerror : function(e) {
         Ti.API.debug(e.error);
         error.call(scope || this, errormessage);
     },
     timeout : 5000  // in milliseconds
   });
   // Prepare the connection.
   client.open("GET", url);
   // Send the request.
   client.send(); 
 }
 RequestProvider = new RequestProvider();
 module.exports = RequestProvider;

主なコンセプトは、すべてのリクエスト ロジックを 1 回だけ実行することです。

于 2013-03-05T13:16:01.343 に答える