我有以下功能如何調用Javascript中
function processData(data) {
histograms = data[0].histograms.map(function(data) {
return {
title: data.sample,
dataset: new Plottable.Dataset(),
dataByThreshold: {},
load: function(threshold) {
this.dataset.data(this.dataByThreshold[threshold]);
}
};
});
而且它被調用這樣
processData(input_data);
數據如下:
var input_data = [{
"threshold": 1.5,
"histograms": [{
"sample": "Sample1",
"nof_genes": 26,
"values": [{
"score": 6.7530200000000002,
"celltype": "Bcells"
}, {
"score": 11.432763461538459,
"celltype": "DendriticCells"
}, {
"score": 25.823089615384621,
"celltype": "Macrophages"
}, {
"score": 9.9911211538461551,
"celltype": "gdTCells"
}, {
"score": 7.817228076923076,
"celltype": "StemCells"
}, {
"score": 17.482806923076922,
"celltype": "StromalCells"
}, {
"score": 29.335427692307697,
"celltype": "Monocytes"
}, {
"score": 28.914959615384621,
"celltype": "Neutrophils"
}, {
"score": 13.818888461538467,
"celltype": "NKCells"
}, {
"score": 9.5030688461538464,
"celltype": "abTcells"
}]
}]
}, {
"threshold": 2,
"histograms": [{
"sample": "Sample1",
"nof_genes": 30,
"values": [{
"score": 5.1335499999999996,
"celltype": "Bcells"
}, {
"score": 16.076072499999999,
"celltype": "DendriticCells"
}, {
"score": 46.182032499999998,
"celltype": "Macrophages"
}, {
"score": 6.5895700000000001,
"celltype": "gdTCells"
}, {
"score": 5.3218800000000002,
"celltype": "StemCells"
}, {
"score": 53.643625,
"celltype": "StromalCells"
}, {
"score": 85.1618225,
"celltype": "Monocytes"
}, {
"score": 55.559129999999996,
"celltype": "Neutrophils"
}, {
"score": 7.6717524999999984,
"celltype": "NKCells"
}, {
"score": 6.3277800000000006,
"celltype": "abTcells"
}]
}]
}];
我的問題是我想創建類似的功能。但不是 這Plottable基於
// dataset: new Plottable.Dataset(),
// this.dataset.data(this.dataByThreshold[threshold]);
我想創建匿名函數是這樣的:
dataset2: new function() {},
load2: function(threshold) {
this.dataset2.data(this.dataByThreshold[threshold]);
}
但是,當我想,我得到這個消息:
this.dataset2.data is not a function
什麼是正確的做法?
功能,你想調用哪個,沒有什麼所謂的'data' –
@ArunPJohny:匿名函數返回'nof_genes'.This後是試圖解決這個相關的帖子:http://stackoverflow.com/questions/34588069/how-to-make-label-in-histogram-respond-to-dynamic-user-input – neversaint
也許你想要這樣使用它:' dataset2:{data:new function(){...}'} –