我正在使用electron-json-storage在电子应用中读取/写入json文件和ngElectron。电子json存储指南读取:
storage.get('foobar', function(error, data) {
if (error) throw error;
console.log(data);
});
使用ngElectron从角度调用该函数时,它在控制台中打印正常,但是如何让对象将其存储在范围中并稍后使用?
答案 0 :(得分:0)
所以我发现了怎么做
在电子部分我不得不返回一个承诺
max = 29472
min = 18792
california = 23364
county = 24132
# county = 18792
min_label = paste0("$", format(min, big.mark = ","))
max_label = paste0("$", format(max, big.mark = ","))
california_label = paste0("$", format(california, big.mark = ","))
county_label = paste0("$", format(county, big.mark = ","))
# Define needle points
perDeg = (max - min)/180
degs = round((county - min)/perDeg, digits = 0)
deg2rad <- function(deg) { deg * pi / 180 }
# Define [x2,y2] - the needle point
x1 = round(0.5 + (0.2 * cos(deg2rad(180-degs))), digits = 3)
y1 = round(0.5 + (0.2* sin(deg2rad(180-degs))), digits = 3)
basePlot <- plot_ly(
type = "pie",
values = c(40, 10, 40, 10),
labels = c(" ", min_label, " ", max_label),
rotation = 108,
direction = "clockwise",
hole = 0.7,
textinfo = "label",
textposition = "outside",
hoverinfo = "none",
domain = list(x = c(0, 1), y = c(0, 1)),
# marker = list(colors = c('rgb(100, 100, 255)', 'rgb(100, 100, 255)', 'rgb(100, 100, 255)', 'rgb(100, 100, 255)')),
showlegend = FALSE,
sort = FALSE
)
basePlot <- add_trace(
basePlot,
type = "pie",
values = c(50, 50),
labels = c("Estimated Annual Cost of Living", " "),
rotation = 90,
direction = "clockwise",
hole = 0.7,
textinfo = "label",
textposition = "inside",
hoverinfo = "none",
domain = list(x = c(0, 1), y = c(0, 1)),
# marker = list(colors = c('rgb(255, 255, 255)', 'rgb(255, 255, 255)')),
showlegend= FALSE
)
basePlot <- layout(
basePlot,
shapes = list(
list(
type = 'path',
path = paste0('M 0.5 0.5 L ', x1, ' ', y1, ' Z'),
xref = 'paper',
yref = 'paper',
fillcolor = 'rgb(226,210,172)'
)
),
annotations = list(
list(
xref = 'paper',
yref = 'paper',
x = 0.5,
y = 0.4,
showarrow = FALSE,
text = paste0('<b>', county_label, '</b>')
)
)
)
basePlot
角度部分
var deferred = q.defer();
storage.get('local Storage', function (error, data) {
if (error) {
throw error;
deferred.reject({'status': 500, 'result': {}, 'error': error});
}
deferred.resolve({'status': 200, 'result': data});
});
return deferred.promise;