这是jsfiddle的链接
http://jsfiddle.net/jaimem/RPGPL/2/
Run Code Online (Sandbox Code Playgroud)
现在,图表显示了所有圆圈的红色.这是一种在圆圈上显示随机颜色的方法.
这是d3.js代码
var data = [{ "count": "202", "year": "1590"},
{ "count": "215", "year": "1592"},
{ "count": "179", "year": "1593"},
{ "count": "199", "year": "1594"},
{ "count": "134", "year": "1595"},
{ "count": "176", "year": "1596"},
{ "count": "172", "year": "1597"},
{ "count": "161", "year": "1598"},
{ "count": "199", "year": "1599"},
{ "count": "181", "year": "1600"},
{ "count": "157", "year": "1602"},
{ "count": "179", "year": "1603"},
{ "count": "150", "year": "1606"},
{ "count": "187", "year": "1607"},
{ "count": "133", …Run Code Online (Sandbox Code Playgroud) 我试图将$ scope变量值作为属性传递给自定义指令,但它不起作用.
这是HTML代码:
<ul ng-repeat="q in questions">
<li>
{{q.question}}
<check-list name="{{q.id}}"></check-list>
</li>
</ul>
Run Code Online (Sandbox Code Playgroud)
该指令是<check-list name={{q.id}}></check-list>,这里是指令代码:
app.directive('checkList',function(){
return {
restrict:'E',
template: function(elem,attrs){
console.log(attrs.name);
return '</br> <input type="radio" /> Yes </br> <input type="radio" /> No'
},
link:function(scope,elem,attrs){
}
};
})
Run Code Online (Sandbox Code Playgroud)
我正在记录属性,attrs.name但我得到的值"{{q.id}}"不是实际值q.id
javascript angularjs angularjs-directive angularjs-ng-repeat
我正在尝试使用AngularJS调用本地运行的REST API.这是AngularJS代码:
$http.defaults.headers.common = {"Access-Control-Request-Headers": "accept, origin, authorization"};
$http.defaults.headers.common['Authorization'] = 'Basic amF5M2RlYzpqYXk=';
$http({method: 'GET', url: 'http://127.0.0.1:5000/user/jay3dec'}).
success(function(data, status, headers, config) {
}).
error(function(data, status, headers, config) {
alert(data);
});
Run Code Online (Sandbox Code Playgroud)
但我在浏览器控制台中遇到错误:
Refused to set unsafe header "Access-Control-Request-Headers"
Run Code Online (Sandbox Code Playgroud)
我尝试使用CURL 查询调用运行在http://127.0.0.1:5000/user/jay3dec上的REST API .
curl -H "Origin: http://127.0.0.1:8000" -H "Authorization: Basic amF5M2RlYzpqYXk=" http://127.0.0.1:5000/user/jay3dec --verbose
Run Code Online (Sandbox Code Playgroud)
它给出了以下输出:
> GET /user/jay3dec HTTP/1.1
> User-Agent: curl/7.35.0
> Host: 127.0.0.1:5000
> Accept: */*
> Origin: http://127.0.0.1:8000
> Authorization: Basic amF5M2RlYzpqYXk=
>
* HTTP 1.0, assume close after …Run Code Online (Sandbox Code Playgroud) 我在尝试运行我的应用程序时收到此错误...
The redirect URI in the request: http://localhost:8080/oauth2callback did not match a registered redirect URI
Run Code Online (Sandbox Code Playgroud)
在谷歌API控制台中,我已经注册了我的重定向网址
Redirect URIs: http://localhost:8080/
Run Code Online (Sandbox Code Playgroud)
在client_secrets.json中我也使用与重定向url相同的内容我正在按照本教程 https://developers.google.com/bigquery/articles/dashboard#addoauth2
编辑:
我刚刚对现有代码进行了一些更改
现在
redirect URIs in API console is http://localhost:8080/oauth2callback
Run Code Online (Sandbox Code Playgroud)
这是我的app.yaml
application: hellomydashboard
version: 1
runtime: python
api_version: 1
handlers:
- url: /favicon\.ico
static_files: favicon.ico
upload: favicon\.ico
- url: /oauth2callback
script: oauth2client/appengine.py
- url: .*
script: main.py
Run Code Online (Sandbox Code Playgroud)
现在虽然它没有显示任何错误,但它显示一个空白页面.
这是我的main.py
from bqclient import BigQueryClient
import httplib2
import os
from google.appengine.api import memcache
from google.appengine.ext import webapp
from google.appengine.ext.webapp.util import run_wsgi_app …Run Code Online (Sandbox Code Playgroud) 这是我的python代码的一部分:
@app.route("/<int:param>/")
def go_to(param):
return param
Run Code Online (Sandbox Code Playgroud)
上面的函数路由一个url,例如www.example.com/12这个函数.
如何声明参数规则以将以整数结尾的URL重定向www.example.com/and/boy/12到此函数?
我正在使用Flask框架.
这是我的日志写入功能:
public static void WriteLog(string source, string message)
{
string logFilePath = @"C:\LogFile\log.txt";
using (StreamWriter sw = new StreamWriter(logFilePath, true))
{
sw.Write(source + ": :" + message);
}
}
Run Code Online (Sandbox Code Playgroud)
但是这段代码有时会导致我错误:
该进程无法访问该文件,因为该文件正由另一个进程使用
所以我修改了我的代码,这是我的新代码:
public static void WriteLog(string source, string message)
{
object _lock = new object();
lock (_lock)
{
string logFilePath = @"C:\LogFile\log.txt";
using (StreamWriter sw = new StreamWriter(logFilePath, true))
{
sw.Write(source + ": :" + message);
}
}
}
Run Code Online (Sandbox Code Playgroud)
虽然我在使用此代码后没有收到错误.但我仍然想知道这是否正确使用锁来防止由于死锁导致的错误,以及我使用锁的方式是否正确.
可能重复:
检测浏览器中的后退按钮
我有两个页面,Page1和Page2.当通过单击链接从Page1移动到Page2时,我倾向于存储在Page2上单击浏览器后退按钮时恢复Page1状态所需的条件.
我使用以下函数来清除缓存,
protected override void OnInit(EventArgs e)
{
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.Cache.SetNoStore();
Response.Cache.SetExpires(DateTime.MinValue);
base.OnInit(e);
}
Run Code Online (Sandbox Code Playgroud)
这样我就可以根据cookie中存储的条件重新加载页面.但问题是如何确定我是否按下浏览器后退按钮或菜单链接来到Page1.
更新:
我刚刚登陆此链接检测浏览器中的后退按钮,但它对我不起作用
首先,我得到了一个答案:静态构造函数的用途是什么?,但我想在这方面得到答案.
这是我的C#静态类:
public static class BasicClass
{
static int i = 0;
static BasicClass()
{
i = 10;
}
public static void Temp()
{
//some code
}
public static void Temp1()
{
//some code
}
}
Run Code Online (Sandbox Code Playgroud)
在这里我有一个静态变量i,在第一次调用时初始化为10.所以基本上它可能是静态构造函数的目的,但是如果不通过初始化声明静态构造函数来实现同样的事情,那么static int i = 10
它只能被初始化一次.
那为什么我们需要一个静态构造函数呢?或者我在理解静态构造函数的概念或使用方面完全错误了吗?
这是我的AngularJs指令.它''希望在模板中显示div,但在代码运行时它没有显示任何内容.
这是html
<div ng-app="SuperHero">
<SuperMan></SuperMan>
</div>
Run Code Online (Sandbox Code Playgroud)
这是AngularJS指令
var app = angular.module('SuperHero',[]);
app.directive('SuperMan',function(){
return{
restrict:'E',
template: '<div>Hello fromt Directive</div>'
}
});
Run Code Online (Sandbox Code Playgroud)
这是演示
我正在使用Node.js开发一个网站(使用Express框架).为了使用Twitter身份验证,我使用passport模块(http://passportjs.org),并将他的Twitter包装器称为passport-twitter.
我的服务器端脚本是:
/**
* Module dependencies.
*/
var express = require('express')
, routes = require('./routes')
, user = require('./routes/user')
, http = require('http')
, path = require('path')
, passport = require('passport')
, keys = require('./oauth/keys')
, TwitterStrategy = require("passport-twitter").Strategy;
var app = express();
app.configure(function(){
app.set('port', process.env.PORT || 3000);
app.set('views', __dirname + '/views');
app.set('view engine', 'jade');
app.use(express.favicon());
app.use(express.logger('dev'));
app.use(express.bodyParser());
app.use(express.methodOverride());
app.use(express.cookieParser('foo'));
app.use(express.session());
// Initialize Passport! Also use passport.session() middleware, to support
// persistent login sessions (recommended).
app.use(passport.initialize()); …Run Code Online (Sandbox Code Playgroud)