0

I am trying to work Ember with Parse.com using ember-model-parse-adapter by samharnack.

I add added a function to make multiple work search(like search engine) for which I have defined a function on cloud using Parse.Cloud.define and run from client. The problem is the Array that my cloud response returns is not compatible with Ember Model because of two attributes they are __type and className. how can I modify the response to get response similar to that i get when I run a find query from client. i.e without __type and className

Example responses for 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

      }
   ]
}
Rigel
  • 882
  • 1
  • 11
  • 32

2 Answers2

2

Thanks Vlad something like this worked for me for array

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: ""
                    });
                }
Rigel
  • 882
  • 1
  • 11
  • 32
0

In your cloud code before you make any response, create and object and extract from it the attributes/members you need and then response it. like so:

//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);
}

on the response side you will get {"result": {"name": "jhon", "age": "26", "id": "zxc123s21"}}

Hope this would help you

vlio20
  • 8,955
  • 18
  • 95
  • 180