I have optimized AJAX calls in REASTAdapter to recover data from the vertx bus bridge. However, I have a problem getting back the promise in the part of the success of the processing request.
I think the problem is in the form of data structure, which Amber expects. This is my adapter's code:
var VertxAdapter = DS.RESTAdapter.extend ({protocol: 'http', host: 'localhost', port: '4200', address mapping: {" Received local host / mindmap ":" mindMaps.list "}, pendingRequests: [], vertx: function () {var adapter = this, if (typeof adapter._vertx === 'undefined') {adapter._vertx = new vertx Eventbus (adapter.prococol + '::' + adapter.host + ':' + adapter.port + '/ eventbus'); console.log ('get started'); adapter._vertx.onopen = function () { // TODO: To send the register messages to this client adapter.processPendingRequests.apply (adapter) server;}}} Adapter._vertx;}, ajax: function (url, type, parameter) {console.log (url, type, parameter); adapter = this; on messageAddress = adapter.addressMapping [+ type "" + url]; Returned new Ember.RSVP.Promise (function (resolution, reject) {var success = function (JSON) {Ember.ru N (empty, resolution, Jason);} error = function (jsn) {amber rows (tap) , Reject, Jason);}; If (adapter.vertx () ReadyState === vertx.EventBus.OPEN) {console.log ('ready state'); Adapter.processRequest (message address, parameter, success, error); } Else {var pendingReq = {address: messageAddress, params: params, success: success, error: error}; Console.log ('Pull Pending Request'); Adapter.pendingRequests.push (pendingReq); }}); }, ProcessPendingRequests: function () {console.log ('processPendingRequests'); Var adapter = this; Adapter.pendingRequests.for each (function (request) {console.log (req); adapter.processRequest (req.address, req.params, req.success, req.error);}); }, ProcessRequest: function (address, parameter, success, error) {console.log (address, parameter, success, error); Var adapter = this; Adapter.vertx (). Send (Address, Parameter, Function (JSN) {// TODO: //console.log Apply; Plugers); Console.log (json.stringify (json)); Success (json); // error (JSN);}); Adapter.pendingRequests = []; }}); Export Default VertxAdapter.extend ({port: '8080'});
And this is the server:
var eventBus = is required ("vertx / event_bus"); Var minds = {}; Var extension = function (obj, props) {for (different prop for prop) {if (props.hasOwnProperty (prop)) {obj [prop] = props [prop]; }} Return obj; }; EventBus.registerHandler ("mindMaps.list", function (args, reply) {reply ({{"data": Object.keys (mindmap) .map (function) {extension of return ({{"type": "mindmap" }, Mindmaps [key];})}};}; eventBus.registerHandler ("mindMaps.save", function (mindmap, reply) {if (mindMap.id) {mindMap.id = Math.floor ((math .random () * 100) +1);;} Mindmap [mindmap.id] = brain micrope; respondent ({"data": manmap}};}); EventBus.registerHandler ("mindmaps.delete", function , Response) {remove mind maps [args.id]; respondent ({});});
console here Usage:
{"data": [{"type": "mindmaps", "name": "one", "id": 59}, {"type": "mindmap" "Name": "two", "id" 99}, {"type": "mindmap", "name": "three", "id": 55}]} warning: the "data" is in payload , But no model model was found for the name "assumed" (resolution taken by the name of the model serializer: remaining: error processing route during :typeForRoot ("data")): brain-map analysis failed: The answer from search should be an array, should not be undefined. Error: Prohibition failure: Feedback by search All should be an array, should not be undefined
I suppose I do not return data from the server in any form which amber hopes me Does.
Thoughts?
BR, MATCH
Unless you want to create your own serializer , Then your JSON should be in a specific format. You can see formatted documents.
If you are not able to return your server to that JSON format, then you have to type it yourself, and change your data in the format listed.
If it seems a little bit, then that's because it is because it is. I think the amber-data adapter and serializer are a problem. Unfortunately, there are not many easy ways for what you want to do.
No comments:
Post a Comment