我的课程结构如下:
public class MyList: List<MyClass>
{
internal static bool isConfigured;
// singleton
public MyList()
{
if (!MyList.isConfigured)
{
lock ("isConfigured")
{
if (!MyList.isConfigured)
{
// add some elements to MyList parsing them from an XML
[..]
MyList.isConfigured = true;
}
}
}
}
public static MyClass MyStaticMethod(int argument)
{
foreach (MyClass c in new MyList())
{
// do something
}
return // an instance of MyClass
}
}
Run Code Online (Sandbox Code Playgroud)
当我从单例外部调用MyList.MyStaticMethod()时,我得到以下异常:
[..]
MyClass mc = MyList.MyStaticMethod(1));
[..]
An object reference is required …Run Code Online (Sandbox Code Playgroud) 从页面file://localhost/Users/pistacchio/dev/epress/catflow/test_html/index.html我有以下(coffeescript)代码试图访问iframe:
$('#ipad-viewport iframe').bind 'load', () ->
console.log $(this).contents().find('map')
Run Code Online (Sandbox Code Playgroud)
(这转换为以下javascript,但我不认为这个问题依赖于此):
(function() {
$('#ipad-viewport iframe').bind('load', function() {
return console.log($(this).contents().find('map'));
});
}).call(this);
Run Code Online (Sandbox Code Playgroud)
我等待加载iframe页面并尝试访问其正文中的元素.我收到以下错误:
Unsafe JavaScript attempt to access frame with URL file://localhost/Users/pistacchio/dev/epress/catflow/test_html/catalogo/catalog/intro.html from frame with URL file://localhost/Users/pistacchio/dev/epress/catflow/test_html/index.html. Domains, protocols and ports must match.
Run Code Online (Sandbox Code Playgroud)
现在,因为iframe定义如下:
<iframe src="file://localhost/Users/pistacchio/dev/epress/catflow/test_html/catalogo/catalog/intro.html" width="1024" height="768"></iframe>
Run Code Online (Sandbox Code Playgroud)
我的网页和iframe不在同一个域中,还是file://localhost?为什么我遇到这个问题?
哦,如果相关,我正在使用Chrome 18进行测试.
这是在我的settings.py中定义的
TEMPLATE_CONTEXT_PROCESSOR = (
"django.core.context_processors.request", # <- HERE
"django.contrib.auth.context_processors.auth",
"django.core.context_processors.debug",
"django.core.context_processors.i18n",
"django.core.context_processors.media",
"django.core.context_processors.static",
"django.core.context_processors.tz",
"django.contrib.messages.context_processors.messages",
)
Run Code Online (Sandbox Code Playgroud)
这是在我的视图文件中:
def home(request):
ctx = {}
request.session['test'] = 1
return render(request, 'home.html', ctx)
# return render_to_response('home.html', ctx,
# context_instance=RequestContext(request))
Run Code Online (Sandbox Code Playgroud)
如果我尝试从模板访问请求对象(例如{{ request.session.test }},未显示任何内容。Django调试工具栏显示django.core.context_processors.request未在CONTEXT_PREPROCESSOR 中添加。有什么帮助吗?
如何存储这样的格式字符串
s = "test with #{value}"
Run Code Online (Sandbox Code Playgroud)
所以以后我可以这样做
puts s % {:value => 'hello'}
Run Code Online (Sandbox Code Playgroud)
如果我写第一件事,就会抱怨value找不到(真的,我想稍后提供).如果我使用原始字符串s = 'test with #{value}',则不进行插值.
我特意试过这个:
@format_html = "<a href=\"http://boardgamegeek.com/user/%{who.sub ' ', '+'}\">%{who}</a> receives <a href=\"%{got[0]}\">%{got[1]}</a> from <a href=\"http://boardgamegeek.com/user/%{from.sub ' ', '+'}\">%{from}</a> and sends <a href=\"%{given[0]}\">%{given[1]}</a> to <a href=\"http://boardgamegeek.com/user/%{to.sub ' ', '+'}\">%{to}</a>"
puts @format_html % {:who => 'who',
:given => 'given',
:from => 'from',
:got => 'got',
:to => 'to'}
Run Code Online (Sandbox Code Playgroud)
我明白了
KeyError (key{who.sub ' ', '+'} not found):
Run Code Online (Sandbox Code Playgroud) 我有这个div:
<div id="test">
{{? a && b || c < 0}}
<div>Pece &alt; Love!</div>
{{?}}
</div>
Run Code Online (Sandbox Code Playgroud)
我知道它的内容就像上面报道的那样(花括号语法是模板引擎).
不幸的是,.html()和.text()都不起作用:
// $('#test').text()
{{? a && b || c < 0}}
Pece &alt; Love!
{{?}}
Run Code Online (Sandbox Code Playgroud)
.text()删除了标签
// $('#test').html()
{{? a && b || c < 0 }}
<div>Pece &alt; Love!</div>
{{?}}
Run Code Online (Sandbox Code Playgroud)
.html()对&符号(和<>)进行编码.
有帮助吗?谢谢
我有一个带向量的结构,我需要存储指向其中一个项目的指针.有了赤裸的指针,我会这样做:
#include <iostream>
#include <vector>
#include <memory>
#include <unistd.h>
struct A {
A () {
v = {1, 2, 3, 4};
uv = &v.front();
}
std::vector<int> v;
int* uv;
};
int main()
{
A a;
std::cout << *a.uv << std::endl;
return 0;
}
Run Code Online (Sandbox Code Playgroud)
现在,我可以摆脱赤裸的指针make_shared:
struct A {
A () {
v = {1, 2, 3, 4};
uv = std::make_shared<int>(v.front());
}
std::vector<int> v;
std::shared_ptr<int> uv;
};
Run Code Online (Sandbox Code Playgroud)
由于C++ 11还没有实现make_unique,我如何使用unique_ptr做同样的事情?我试图通过使分配前元uv一个unique_ptr,并呼吁uv.reset(&v.front());,但我得到了以下错误:
malloc: *** error for object …Run Code Online (Sandbox Code Playgroud) 我有“post”对象和一个“post like”对象,其中包含哪个用户收到了多少赞:
class Post(models.Model):
text = models.CharField(max_length=500, default ='')
user = models.ForeignKey(User)
class PostLike(models.Model):
user = models.ForeignKey(User)
post = models.ForeignKey(Post)
Run Code Online (Sandbox Code Playgroud)
我可以像这样选择帖子收到的赞数:
Post.objects.all().annotate(likes=Count('postlike'))
Run Code Online (Sandbox Code Playgroud)
这大致翻译为:
SELECT p.*,
Count(l.id) AS likes
FROM post p, postlike l
WHERE p.id = l.post_id
GROUP BY (p.id)
Run Code Online (Sandbox Code Playgroud)
有用。现在,我如何过滤Count当前用户的聚合?我想不检索所有岗位的喜欢,但都喜欢通过登录的用户。生成的 SQL 应该是这样的:
SELECT p.*,
(SELECT COUNT(*) FROM postlike WHERE postlike.user_id = 1 AND postlike.post_id = p.id) AS likes
FROM post p, postlike l
WHERE p.id = l.post_id
GROUP BY (p.id)
Run Code Online (Sandbox Code Playgroud) 我可以使用以下代码获取已排序的文件名列表:
$log_files = scandir(LLP_LOG_DIR);
$sorted = sort($log_files);
Run Code Online (Sandbox Code Playgroud)
文件名格式为X.log,其中X是渐进数值.
我怎样才能解决获得的问题
0.log
1.log
10.log
11.log
2.log
3.log
Run Code Online (Sandbox Code Playgroud)
想要的结果在哪里
0.log
1.log
2.log
3.log
[..]
9.log
10.log
11.log
[..]
Run Code Online (Sandbox Code Playgroud)
我可以删除".log"字符串,对它们进行排序等,但最有效的方法是什么?
如果我有这个json结构:
var j = {
param1: 'hello',
param2: 'world',
func: function() {
console.log(this.param1 + ' ' + this.param2);
}
};
Run Code Online (Sandbox Code Playgroud)
thisin func未定义.如何在这个json对象中访问self?谢谢
编辑:
我正在尝试:
j.func();
Run Code Online (Sandbox Code Playgroud)