我正在构建一个应用程序,使用 Rails 和 Backbone 作为后端,需要用户登录才能访问某些页面。在经过用户身份验证的页面之一上,我进行了设置,以便他们可以通过输入数据在我的数据库中创建一个条目,然后将其发送到 Google 地图 API 以检索纬度和经度。
通过辅助函数,我检查用户是否经过身份验证,但是当我向 Google Maps API 发送 AJAX 调用时,用户令牌也会被发送。这是我现在设置的代码。
在我的 api js 文件中,该文件首先在页面加载时运行
var token = $('#api-token').val();
$.ajaxSetup({
headers:{
"accept": "application/json",
"token": token
}
});
Run Code Online (Sandbox Code Playgroud)
在我的 users_controller.rb 中
def profile
authorize!
@user = current_user
@bathrooms = Bathroom.all.sort_by { |name| name }
render layout: 'profile_layout'
end
def authorize!
redirect_to '/login' unless current_user
end
def current_user
@current_user ||= User.find(session[:user_id]) if session[:user_id]
end
Run Code Online (Sandbox Code Playgroud)
这是我的 AJAX 调用
function getInfo(location) {
console.log('getInfo');
$.ajax({
method: 'get',
url: 'https://maps.googleapis.com/maps/api/geocode/json',
data:{address: …Run Code Online (Sandbox Code Playgroud) 所以我正在使用 PivotTable.js,它对工作有很大帮助。
不过现在,我正在尝试让过滤器根据值更改单元格或单元格内字体的颜色。
例如,如果我的数据集中有一组日期
dates = ["N/A", "4/12/2016", "7/9/2024", "7/9/2024", "4/1/2013"]
Run Code Online (Sandbox Code Playgroud)
我想在 2016 年 6 月 1 日之前的任何日期更改颜色。
如果这有什么不同,我将我的数据作为变量“数据”在本地传递
$(function(){
var derivers = $.pivotUtilities.derivers;
var renderes = $.extend($.pivoUtilities.renderers, $.pivotUtilities.export_renderers);
$("#pivot_table").pivotUI(data, {
derivedAttributes: function(data){
// not sure how to access the css of the element from here
}
rows: [],
cols: ["Name", "Date", "Organization", "Cost"],
renderers: renderers,
rendererName: "Table"
});
});
Run Code Online (Sandbox Code Playgroud)
我试过进入衍生属性,但我尝试的一切都不起作用。
任何帮助或头脑风暴将不胜感激