Parse.com操纵响应对象

时间:2013-07-29 19:47:35

标签: parse-platform ember-model

我正在尝试使用Parse.com与Ember合作 samharnack ember-model-parse-adapter

我添加了一个函数来进行多个工作搜索(比如搜索引擎),我已经使用Parse.Cloud.define在云上定义了一个函数并从客户端运行。 问题是我的云响应返回的数组与Ember模型不兼容,因为它们是__type和className这两个属性。如何修改响应以获得类似于从客户端运行查询查询时获得的响应。即没有__type和className

示例回复 对于App.List.find()= { "results":[ { "text":"zzz", "words":[ "zzz" ], "createdAt":"2013-06-25T16:19:04.120Z", "updatedAt":"2013-06-25T16:19:04.120Z", "objectId":"L1X55krC8x" } ] }

for App.List.cloudFunction(“sliptSearch”,{“text”: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 个答案:

答案 0 :(得分:2)

感谢Vlad这样的数组

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: ""
                    });
                }

答案 1 :(得分: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"}}

希望这会对你有所帮助