在我的AngularJS应用程序中,route当用户未登录时,我将重定向到特定页面.要做到这一点,我正在使用变量$rootScope.
现在我想在用户登录时阻止浏览器的后退按钮.我想将其重定向到特定页面(registration视图).问题是我不知道是否有后退按钮事件.
我的代码是:
angular.module('myApp',[...]
//Route configurations
}])
.run(function($rootScope, $location){
$rootScope.$on('$routeChangeStart', function(event, next, current){
if(!$rootScope.loggedUser) {
$location.path('/register');
}
});
$rootScope.$on('$locationChangeStart', function(event, next, current){
console.log("Current: " + current);
console.log("Next: " + next);
});
});
Run Code Online (Sandbox Code Playgroud)
所以在$locationChangeStart我写一个伪代码,如:
if (event == backButton){
$location.path('/register');
}
Run Code Online (Sandbox Code Playgroud)
可能吗?
一个天真的解决方案是编写一个函数,检查是否next和current错误的顺序,检测用户是否回去.
还有其他解决方案吗?我正以错误的方式解决问题?
我正在写一个崇高的文本插件.我正在尝试在新窗口中打开几个文件.
在sublime text API参考中,我找到了一种打开文件的方法
window.open_file(filepath)
Run Code Online (Sandbox Code Playgroud)
但我没有找到任何打开新窗口的东西.有人可以指点我.我知道这是一个愚蠢的问题,但归咎于文件不足:)
我有很多<input type='text' name='input0' />领域.
用户可以动态添加它们,以便我们得到类似的东西:
<input type='text' name='input0' />
<input type='text' name='input1' />
<input type='text' name='input2' />
Run Code Online (Sandbox Code Playgroud)
...等等.我们不知道会有多少人.提交表单时,我想遍历每个输入字段并将它们分配给$_POST变量.这些不是表单中的唯一输入字段,还有其他元素,如单选按钮,复选框和其他文本字段.我的问题是我需要以某种方式识别这些特定的动态生成的文本字段,并循环它们.当我在服务器端获取的是输入字段的名称时,我该怎么做?
我从客户端调用了30次WebService方法(asmx):
for (var i = 0; i < 30; i++) {
WSCustom.Test(i,
function (res) {
$("#Results").append(res + "<br />");
},
function (res) {
$("#Results").append(res.get_message() + "<br />");
}
);
}
Run Code Online (Sandbox Code Playgroud)
这是WebService方法:
[WebMethod(EnableSession = true)]
public string Test(int i)
{
DateTime m_oStart = DateTime.Now;
WebClient m_oClient = new WebClient();
if (i % 2 == 0)
{
byte[] res = m_oClient.DownloadData("http://www.repubblica.it/");
}
return String.Format("TotalSeconds:{0}", new string[] { DateTime.Now.Subtract(m_oStart).TotalSeconds.ToString() });
}
Run Code Online (Sandbox Code Playgroud)
我的方面是asynch回复.
我的意思是,我应该立即得到15个回复(奇怪的是i它立即返回),并且在剩余的回复期间(需要时间下载页面服务器端).
但事实上,outpup是不同的:它立即处理第一个电话.比,它等待第二个完成,比我收到一些奇怪的i回复,依此类推.
所以它根本不是异步的.
WebServices如何管理.NET中的客户端调用?我可以在整个过程中执行asynch吗?
有了EnableSession …
我无法弄清楚为什么每次循环都没有正确加起来.当输入-9999时,while循环也没有输出和,这也是一个问题.
import java.util.*;
public class list
{
public static void main(String args [])
{
Scanner sc = new Scanner(System.in);
int Number, Sum = 0;
System.out.println("Enter the list of whole numbers, terminate by -9999> ");
Number = sc.nextInt();
Sum += Number;
while (Number != -9999)
{
if (Number > 1 && Number < 100)
{
Sum += Number;
Number = sc.nextInt();
}
else
System.out.println("Please enter a number between 1 and 100");
Number = sc.nextInt();
}
System.out.println("Sum is " + Sum);
} …Run Code Online (Sandbox Code Playgroud) 命令在OSX终端中使用固定的选项顺序.所以,例如,我必须使用rm -rf name,而不是rm name -rf,这对我来说更方便(例如我可以先添加所有名称,然后查看我是否有目录并需要添加-r).
有没有办法让OSX命令更通用的语法?
我不确定这是可能的,但是,例如,我想知道一些shell命令的预处理与... python程序,它将重新格式化选项并调用适当的命令.但我不熟悉python,并且不知道每次编写命令时如何运行这样的程序.
我只是想读一个标准的linux'/ etc/passwd'文件:拆分成记录.这似乎工作(所有行都回显到终端)但最后抛出一个异常?(见下文)
这项计划有什么用?
(use 'clojure.java.io)
(use 'clojure.string)
(defn process_file[infile] (
(defstruct user :username
:password
:uid
:gid
:comment
:home_dir
:shell)
(def record_separator #":")
(with-open [rdr (reader infile)]
(doseq [line (line-seq rdr)]
(def fields (split line record_separator) )
(def user_record (apply struct user fields) )
(println (user_record :username) )
)
)
)
)
; main
(process_file "/etc/passwd")
[ after all the lines read have been output ]
Exception in thread "main" java.lang.ClassCastException: clojure.lang.PersistentStructMap$Def cannot be cast to clojure.lang.IFn
at clojure.lang.Var.fn(Var.java:392)
at clojure.lang.Var.invoke(Var.java:419) …Run Code Online (Sandbox Code Playgroud) 我有一个小型iPhone应用程序,它从社交网络中获取用户信息(名称,城市,性别),然后在视图中显示:

数据以JSON格式到达(请注意sex = 0男性用户):
2014-01-22 21:18:42.915 oauthMailru[697:1303] json=(
{
age = 41;
"app_installed" = 1;
birthday = "08.06.1972";
"first_name" = Alexander;
"friends_count" = 17;
"has_pic" = 1;
"is_friend" = 0;
"is_online" = 0;
"is_verified" = 1;
"last_name" = Farber;
"last_visit" = 1390312557;
link = "http://my.mail.ru/mail/farber72/";
location = {
city = {
id = 855;
name = "Dusseldorf";
};
country = {
id = 46;
name = "Germany";
};
};
nick = "Alexander Farber";
pic = "http://avt.appsmail.ru/mail/farber72/_avatar"; …Run Code Online (Sandbox Code Playgroud) 我在我的机器上安装了NPN,我收到以下错误
curl https://raw.github.com/creationix/nvm/master/install.sh | SH
No command 'npn' found, did you mean:
Command 'npg' from package 'netdisco-backend' (universe)
Command 'nn' from package 'nn' (universe)
Command 'npm' from package 'npm' (universe)
Command 'xpn' from package 'xpn' (universe)
npn: command not found
Run Code Online (Sandbox Code Playgroud) 像这样将比例设置为负数是否有意义?
BigDecimal result;
.
.
.
result = result.setScale(-1, RoundingMode.HALF_UP)
Run Code Online (Sandbox Code Playgroud)
如果你这样做会发生什么?
java ×2
loops ×2
.net ×1
angularjs ×1
asynchronous ×1
back ×1
bigdecimal ×1
boolean ×1
c# ×1
clojure ×1
ios ×1
javascript ×1
json ×1
macos ×1
nested-if ×1
node.js ×1
objective-c ×1
php ×1
redirect ×1
sequence ×1
shell ×1
sublimetext ×1
sublimetext2 ×1
sublimetext3 ×1
web-services ×1
while-loop ×1