Pregunta

¿Estoy haciendo algo completamente mal aquí? Estoy poblando un modelo de columna vertebral a partir de una respuesta JSONP. Cuando veo la primera declaración de la consola en Firebug, el objeto 'actual' tiene 'icono' bajo atributos. Sin embargo, al imprimir console.log(current.has("icon")) Devuelve falso y, por lo tanto, actual.get ("icon") volverá indefinido.

var Current = Backbone.Model.extend({
    url: "A_valid_url",
    sync: function(method, model, options) {
        options.timeout = 10000;
        options.dataType = "jsonp";

        return Backbone.sync(method, model, options);
    },
    parse: function(response, xhr) {
        return response.current_observation;
        }
});

var current = new Current({test: "blah"});
    current.fetch();
    console.log(current);//under attributes there is a "icon"
    console.log(current.has("icon")); //false
    console.log(current.get("icon")); //undefined
    console.log(current.has("test")); //true

No hay solución correcta

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top