我觉得这里有示波器问题,但我很茫然。我无法理解如何将数据从json文件传递到javascript对象。
Data.GetJSON = function() {};
Data.GetJSON.prototype = {
constructor : Data.GetJSON,
request : new XMLHttpRequest(),
// this doesn't seem to be doing what I want
copy : function(source, destination) {
destination = Object.assign({}, source);
window.alert("Copying " + Object.getOwnPropertyNames(source) + " to " + Object.getOwnPropertyNames(destination));
window.alert("Copying " + source.toString() + " to " + destination.toString());
},
call : function(file) {
"use strict";
var adventure = this.adventure;
var copy = this.copy;
this.request.open('GET', file);
this.request.responseType = 'json';
this.request.send();
// I have a scope problem somewhere in here.
this.request.onload = function() {
this.buffer = Object.assign({}, this.response);
Object.keys(this.buffer).forEach(e => console.log(`key=${e} value=${this.buffer[e]}`));
copy(this.buffer, adventure);
};
}
};
这是使我能够在文本冒险中为玩家更新动作结果的功能。例如,在这种情况下,adventure.id应该返回“ 00”。