0
如何獲取應用於數據源的YUI3 sendRequest以返回預定義的對象而不是普通的對象?YUI3返回自定義對象的數據源
例如,我有它的方法該基類:
function Student(id, name){
this.id = id;
this.name = name;
}
Context.prototype.setId = function(id){ this.id = id; };
Context.prototype.setName = function(name){ this.name = name; };
Context.prototype.getId = function(){ return this.id; };
Context.prototype.getName = function(){ return this.name; };
我有這樣的代碼,從一個API檢索數據,歸一化,並返回數據作爲對象:
var studApiDataSource = new Y.DataSource.Get({source: API_URL});
studApiDataSource.plug(Y.Plugin.DataSourceJSONSchema, {
schema: {
resultListLocator: "response.student",
resultFields: ["id","name"]
}
});
var myCallback = function(e) {
Y.Array.each(e.response.results, function(stud){
Y.log(stud.id+' '+stud.name);
}
}
studApiDataSource.sendRequest({
request: "?cmd=getStudents",
callback: {
success: myCallback,
failure: function (e) { }
}
});
由studApiDataSource.sendRequest()檢索並傳遞給myCallback的對象數組是具有id和name屬性的普通對象。然而,我希望這些是學生對象,與他們的成員函數(getId,getName等)