我有两个Angular控制器:
function Ctrl1($scope) {
$scope.prop1 = "First";
}
function Ctrl2($scope) {
$scope.prop2 = "Second";
$scope.both = Ctrl1.prop1 + $scope.prop2; //This is what I would like to do ideally
}
Run Code Online (Sandbox Code Playgroud)
我不能Ctrl1
在里面使用,Ctrl2
因为它是未定义的.但是,如果我尝试传递它...
function Ctrl2($scope, Ctrl1) {
$scope.prop2 = "Second";
$scope.both = Ctrl1.prop1 + $scope.prop2; //This is what I would like to do ideally
}
Run Code Online (Sandbox Code Playgroud)
我收到一个错误.有谁知道如何做到这一点?
干
Ctrl2.prototype = new Ctrl1();
Run Code Online (Sandbox Code Playgroud)
也失败了.
注意:这些控制器不是彼此嵌套的.
我正在使用Vuejs.这是我的标记:
<body>
<div id="main">
<div id="mainActivity" v-component="{{currentActivity}}" class="activity"></div>
</div>
</body>
Run Code Online (Sandbox Code Playgroud)
这是我的代码:
var main = new Vue({
el: '#main',
data: {
currentActivity: 'home'
}
})
;
Run Code Online (Sandbox Code Playgroud)
当我加载页面时,我收到此警告:
[Vue warn]: Cannot find element: #main
Run Code Online (Sandbox Code Playgroud)
我究竟做错了什么?
这是我的代码:
@app.route('/hello', methods=["POST"])
def hello():
resp = make_response()
resp.headers['Access-Control-Allow-Origin'] = '*'
return resp
Run Code Online (Sandbox Code Playgroud)
但是,当我从浏览器向我的服务器发出请求时,我收到此错误:
XMLHttpRequest cannot load http://localhost:5000/hello.
No 'Access-Control-Allow-Origin' header is present on the requested resource.
Run Code Online (Sandbox Code Playgroud)
我也尝试过这种方法,在请求之后设置响应头:
@app.after_request
def add_header(response):
response.headers['Access-Control-Allow-Origin'] = '*'
return response
Run Code Online (Sandbox Code Playgroud)
没有骰子.我犯了同样的错误.有没有办法在路由功能中设置响应头?这样的事情是理想的:
@app.route('/hello', methods=["POST"])
def hello(response): # is this a thing??
response.headers['Access-Control-Allow-Origin'] = '*'
return response
Run Code Online (Sandbox Code Playgroud)
但无论如何我无法做到这一点.请帮忙.
编辑
如果我用这样的POST请求卷曲url:
curl -iX POST http://localhost:5000/hello
Run Code Online (Sandbox Code Playgroud)
我收到了这个回复:
HTTP/1.0 500 INTERNAL SERVER ERROR
Content-Type: text/html
Content-Length: 291
Server: Werkzeug/0.9.6 Python/2.7.6
Date: Tue, 16 Sep 2014 03:58:42 GMT
<!DOCTYPE HTML …
Run Code Online (Sandbox Code Playgroud) 我ez_setup
从这里下载了代码:http://peak.telecommunity.com/dist/ez_setup.py
并运行它,但我认为setuptools
没有正确安装.当我尝试打开一个鸡蛋easy_install
时,我得到一个NameError.有什么想法吗?
这是具体的错误:
Traceback (most recent call last):
File "C:...setup.py", line 223, in <module>
easy_install eggsetup.py
NameError: name 'easy_install' is not defined
Run Code Online (Sandbox Code Playgroud) 这是我的代码:
function ParentCtrl($scope) {
$scope.people = ["Tom", "Dick", "Harry"];
$scope.count = $scope.people.length;
}
function ChildCtrl($scope) {
$scope.parentpeople = ParentCtrl.people //this is what I would like to do ideally
}
Run Code Online (Sandbox Code Playgroud)
我controller
在另一个内嵌一个角.我想将controller
第一个变量传递给第二个变量.有谁知道如何做到这一点?
注意
我做不了类似的事情
ChildCtrl.prototype = new ParentCtrl();
Run Code Online (Sandbox Code Playgroud)
因为我会覆盖该people
属性ChildCtrl
.
我有一个我在这里写的模块:
# Hello.jl
module Hello
function foo
return 1
end
end
Run Code Online (Sandbox Code Playgroud)
和
# Main.jl
using Hello
foo()
Run Code Online (Sandbox Code Playgroud)
当我运行Main
模块时:
$ julia ./Main.jl
Run Code Online (Sandbox Code Playgroud)
我收到此错误:
ERROR: LoadError: ArgumentError: Hello not found in path
in require at ./loading.jl:249
in include at ./boot.jl:261
in include_from_node1 at ./loading.jl:320
in process_options at ./client.jl:280
in _start at ./client.jl:378
while loading /Main.jl, in expression starting on line 1
Run Code Online (Sandbox Code Playgroud) 我想制作一个Java游戏.首先,程序会询问玩家的数量; 之后,它要求他们的名字.我把他们的名字放在HashMap
带有身份证和他们的分数的地方.在比赛结束时我计算得分,我想把它放在HashMap
(特定名称的具体分数)中.有谁知道如何做到这一点?这是我的代码:
玩家:
public class Player {
public Player() {
}
public void setScore(int score) {
this.score = score;
}
public void setName(String name) {
this.name = name;
}
private String name;
private int score;
public Player(String name, int score) {
this.name = name;
this.score = score;
}
public String getName() {
return name;
}
@Override
public String toString() {
return "Player{" + "name=" + name + "score=" + score + '}';
}
public int getScore() …
Run Code Online (Sandbox Code Playgroud) 我是Angular2的新手,我已经习惯了Angular 1摘要周期,这意味着如果我更新视图的范围,我可以通过调用手动触发摘要$scope.$digest()
.但是,我不确定如何在Angular2中执行此操作,因为新框架没有旧版本具有的隐式数据绑定.
这是我的问题.我有一个路由,当一个带有参数的网址被命中时加载一个组件:
// Router
export const AppRoutes : RouterConfig = [
{
path: 'my/:arg/view',
component: MyComponent
}
]
Run Code Online (Sandbox Code Playgroud)
然后我有这个组件:
// Component
export class MyComponent {
constructor(private route : ActivatedRoute,
private r : Router) {
let id = parseInt(this.route.params['value'].id);
console.log(id);
// do stuff with id
}
reloadWithNewId(id:number) {
this.r.navigateByUrl('my/' + id + '/view');
}
}
Run Code Online (Sandbox Code Playgroud)
让我们说我导航到网址/my/1/view
.它将调用构造函数并1
记录数字.但是,如果我reloadWithNewId
使用新的id 调用,reloadWithNewIf(2)
则不会再次调用构造函数.如何手动重新加载组件?
这是我的代码:
var thisValue = new models.Value({
id:id,
title:title //this is a unique value
});
console.log(thisValue);
thisValue.save(function(err, product, numberAffected) {
if (err) {
if (err.code === 11000) { //error for dupes
console.error('Duplicate blocked!');
models.Value.find({title:title}, function(err, docs)
{
callback(docs) //this is ugly
});
}
return;
}
console.log('Value saved:', product);
if (callback) {
callback(product);
}
});
Run Code Online (Sandbox Code Playgroud)
如果我检测到正在尝试插入重复项,我会阻止它.但是,当发生这种情况时,我想返回现有文档.正如你所看到的,我已经实现了一串回调,但这是丑陋的,它是不可预测的(即我怎么知道将调用哪个回调?我如何传递正确的回调?).有谁知道如何解决这个问题?任何帮助赞赏.
这个片段来自Julia 中Rational Numbers的实现:
# Rational.jl
# ...
Rational{T<:Integer}(n::T, d::T) = Rational{T}(n,d)
Rational(n::Integer, d::Integer) = Rational(promote(n,d)...)
Rational(n::Integer) = Rational(n,one(n))
//(x::Rational, y::Integer) = x.num // (x.den*y) <--- HERE!
# ...
Run Code Online (Sandbox Code Playgroud)
查看//
函数如何实现,然后与中缀表示法一起使用?这实际上如何返回一个值?
当我看到这段代码时,我解释如下:
//
使用Rational和Integer调用该函数.#2真的让我很困惑.数据结构中的递归在哪里结束?//
如果不断评估任何值,如何返回值?
请帮我理解这个.