Skip to content

Map does not have parseModel (ajax convert) #18

@justinbmeyer

Description

@justinbmeyer

@lewismoten commented on Wed Oct 12 2016

I'm having a bug pop up. this.parseModel is undefined. This happens when an ajax request completes in jQuery, and CanJS has a proxy to convert the response to a model. In this case, "this" represents the CanJS "Map"

jquery.js - Callback for a completed ajax request...

complete( // complete === jquery.js done
  xhrSuccessStatus[ xhr.status ] || xhr.status, // 200
  xhr.statusText, // "OK"
  ( xhr.responseType || "text" ) !== "text"  ||
  typeof xhr.responseText !== "string" ?
    { binary: xhr.response } :
    { text: xhr.responseText }, // {text: '{"name": "value"}'}
  xhr.getAllResponseHeaders() // Pragma: no-cache, etc.
);                          

jquery.js - done

response = ajaxConvert( s, response, jqXHR, isSuccess );
// ajaxConvert === jquery.js ajaxConvert
// s === (ajax options)
// response === {error: "SyntaxError: Unexpected token o in JSON", state: "parsererror"}
// jqXHR === jqXHR...
// isSuccess === true

jquery.js - ajaxConvert:

response = conv( response ); 
// response ==={error: "..."}
// conv === can/proxy.js class_cb

can/construct/proxy/proxy.js - class_cb

cur = (isString ? self[func] : func).apply(self, cur || []);
// self = Map
// func = "model"
// cur = [{error: "..."}]

Which essentially translates to:

Map.model.call(Map, {error: "..."})

can/model/model.js - model

attributes = this.parseModel(attributes, xhr);
// this === Map
// attributes === {error: "..."}
// xhr === undefined
// this.parseModel === undefined

How can I get "Map" to have "parseModel"?

It appears that this may be a work-around...

attributes = function(attributes){
    return function (attributes) {
        return prop ? can.getObject(prop, attributes) : attributes;
    };
};
//attributes = this.parseModel(attributes, xhr);

@justinbmeyer commented on Tue Apr 11 2017

@lewismoten Anyway you can create an example? Moving to can-model.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions