2013-07-29 38 views
0

我努力工作灰燼與Parse.com。Parse.com使用 <a href="https://github.com/samharnack/ember-model-parse-adapter/blob/master/ember-model-parse-adapter.js" rel="nofollow">ember-model-parse-adapter</a>通過samharnack操縱響應對象

我添加附加功能,使多個工作搜索(如搜索引擎)爲我所用Parse.Cloud.define定義雲的功能,並從客戶端運行。 的問題是,我的雲響應返回不與Ember型號兼容,因爲兩個屬性他們是__type和類名的數組。我如何修改響應以獲得類似於我從客戶端運行查找查詢時獲得的響應。即,沒有__type和類名

實施例響應 爲App.List.find()= { "results":[ { "text":"zzz", "words":[ "zzz" ], "createdAt":"2013-06-25T16:19:04.120Z", "updatedAt":"2013-06-25T16:19:04.120Z", "objectId":"L1X55krC8x" } ] }

爲App.List.cloudFunction( 「sliptSearch」,{ 「文本」:this.get( 「SEARCHTEXT」) })

{ 
    "results":[ 
     { 
     "text":"zzz", 
     "words":[ 
      "zzz" 
     ], 
     "createdAt":"2013-06-25T16:19:04.120Z", 
     "updatedAt":"2013-06-25T16:19:04.120Z", 
     "objectId":"L1X55krC8x", 
     "__type" : Object,    //undesired 
     "className" : "Lists"   //undesired 

     } 
    ] 
} 

回答

2

感謝弗拉德像這樣爲我工作陣列

resultobj = []; 

searchListQuery.find({ 
    success: function(results) { 
     for(var i=0, l=results.length; i<l; i++) { 
      temp = results.pop(); 
        resultobj.push({ 
         text: temp.get("text"), 
         createdAt: temp.createdAt, 
         updatedAt: temp.updatedAt, 
         objectId: temp.id, 
         words: "", 
         hashtags: "" 
        }); 
       } 
0

在您的雲代碼作出任何響應之前,請創建並從中提取所需的屬性/成員,然後對其進行響應。像這樣:

//lets say result is some Parse.User or any other Parse.Object 
function(result) 
{ 
    var responseObj = {}; 
    responseObj.name = responseObj.get("name"); 
    responseObj.age = responseObj.get("age"); 
    responseObj.id = responseObj.id; 

    response.success(responseObj); 
} 

在響應方面,你會得到{"result": {"name": "jhon", "age": "26", "id": "zxc123s21"}}

希望這會幫助你

相關問題