我需要创建一个只能执行一次的函数,每次执行后都不会执行.我从C++和Java中了解到可以完成工作的静态变量,但我想知道是否有更优雅的方法来做到这一点?
我正在尝试使用angular 2 cli.
我想在我的项目中使用momentjs,所以这就是我所做的:
1.使用angular cli创建项目.
2.运行npm install --save moment
3.从src文件夹运行typings init
+ typings install --save moment
.
4.增加系统模块的时刻:
System.config({
packages: {
app: {
format: 'register',
defaultExtension: 'js'
},
moment: {
map: 'node_modules/moment/moment.js',
type: 'cjs',
defaultExtension: 'js'
}
}
});
Run Code Online (Sandbox Code Playgroud)
import * as moment from 'moment';
到我想要的组件.ng serve
和得到:[DiffingTSCompiler]:Typescript发现以下错误:app/angular-day-picker.ts(2,25):找不到模块'时刻'.错误:[DiffingTSCompiler]:Typescript发现以下错误:app/angular-day-picker.ts(2,25):找不到模块'时刻'.在diffingTSCompiler.rebuild(/ Users/vioffe/personal /)的DiffingTSCompiler.doFullBuild(/Users/vioffe/personal/angular-day-picker/node_modules/angular-cli/lib/broccoli/broccoli-typescript.js:202:29) diffingPluginWrapper.rebuild上的angular-day-picker/node_modules/angular-cli/lib/broccoli/broccoli-typescript.js:101:18)(/ Users/vioffe/personal/angular-day-picker/node_modules/angular-cli/lib/broccoli/diffing-broccoli-plugin.js:87:45)at/Users/vioffe/personal/angular-day-picker/node_modules/angular-cli/node_modules/angular-cli/node_modules/broccoli/lib/api_compat. js:42:21 at lib $ rsvp $$ internal $$ tryCatch(/Users/vioffe/personal/angular-day-picker/node_modules/angular-cli/node_modules/angular-cli/node_modules/rsvp/dist/rsvp.js :1036:16)在lib $ rsvp $$ internal $$ invokeCallback(/Users/vioffe/personal/angular-day-picker/node_modules/angular-cli/node_modules/angular-cli/node_modules/rsvp/dist/rsvp.js :1048:17)at/users/vioffe/personal/angular-day-picker/node_modules/angular-cli/node_modules/angular -cli/node_modules/rsvp/dist/rsvp.js:331:11 at lib $ …
如何检查设备是否有摄像头(手电筒).我在谈论Android操作系统的设备?
我已经看到了一些解决方案,这些解决方案讨论了如何打开和关闭LED,但如果设备甚至没有LED,会发生什么.
打开我正在使用的相机 camera.open()
在我的应用程序中收到通知后,单击它会打开活动B.活动B有一个父活动A.这是清单:
<activity
android:name="com.evapp.activities.B"
android:label="@string/title_activity_B"
android:parentActivityName="com.evapp.activities.A"
android:screenOrientation="portrait" >
<!-- Parent activity meta-data to support 4.0 and lower -->
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.evapp.activities.A" />
</activity>
Run Code Online (Sandbox Code Playgroud)
在活动BI中启用了向上功能(活动操作栏图标旁边的左箭头),这里是代码:
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
getActionBar().setDisplayHomeAsUpEnabled(true);
...
Run Code Online (Sandbox Code Playgroud)
问题是,如果通过点击通知打开活动B(活动A不是带来活动B的活动),则点击图标时关闭应用程序.我想打开它的父母活动,A.有可能吗?或者我应该startActivity()
从活动B中做到这一点?
更新1-我已添加此代码:
@Override
public boolean onOptionsItemSelected(MenuItem item)
{
switch (item.getItemId())
{
case android.R.id.home:
Intent upIntent = NavUtils.getParentActivityIntent(this);
if (NavUtils.shouldUpRecreateTask(this, upIntent))
{
TaskStackBuilder.create(this)
.addNextIntentWithParentStack(upIntent)
.startActivities();
}
else
{
NavUtils.navigateUpTo(this, upIntent);
}
return true;
Run Code Online (Sandbox Code Playgroud)
谢谢
是否有可能同时使用执行更新Criteria
的Hibernate
?例如:
Session session = getSession();
Criteria crit = session.createCriteria(User.class);
crit.add(Restrictions.eq("token", sessionToken));
User user= new User();
Transaction tx = session.getTransaction();
try
{
tx.begin();
session.updateWithCriteria(user, crit); //my imaginary function
tx.commit();
}
catch (Exception e)
{
e.printStackTrace();
tx.rollback();
}
session.close();
Run Code Online (Sandbox Code Playgroud) 我试图在几天内运行一些单元测试但没有成功.我的应用程序是用typescript编写的(单元测试也是用typescript编写的).这是我的业力配置文件:
module.exports = function (config) {
config.set({
basePath: "../../../../",
frameworks: [
"jasmine",
"systemjs"
],
browsers: ['PhantomJS'],
singleRun: true,
reporters: ['progress'],
systemjs: {
config: {
paths: {
systemjs: "src/main/webapp/static/js/engage/lib/bower/system.js/dist/system.src.js",
typescript: "build/node_modules/typescript/lib/typescript.js"
},
transpiler: "typescript"
},
// testFileSuffix: ".spec.ts"
},
files: [
'src/main/webapp/static/js/engage/dist/vendor/vendor.min.js',
'src/main/webapp/static/js/engage/lib/bower/system.js/dist/system-polyfills.src.js',
'src/main/webapp/static/js/engage/lib/bower/angular-mocks/angular-mocks.js',
{pattern: "src/main/webapp/static/js/engage/app/**/*.spec.ts", served: true, included: false}
]
});
};
Run Code Online (Sandbox Code Playgroud)
当我运行时,karma start
我收到以下错误:
05 09 2016 21:39:45.543:INFO [karma]: Karma v1.2.0 server started at http://localhost:9876/
05 09 2016 21:39:45.546:INFO [launcher]: Launching browser PhantomJS with unlimited concurrency
05 09 …
Run Code Online (Sandbox Code Playgroud) 我想将这个库从github 包含到我现有的项目中,我正在使用eclipse.有没有关于如何做到这一点的教程?我是android和java开发的新手,所以任何一步一步的帮助都会很棒!
注意:我在eclipse中安装了一个Egit插件.
我尝试从github页面下载的解压缩文件导入库时屏幕的图像:
在导入库之后,如下所示,在我的Package Explorer中创建的库文件夹,但这是我得到的:
我现在在eclipse Package explorer中有了库,现在我想将它添加到我的项目中,所以我右键单击现有项目并选择属性.在Android liabrary下我点击确定并选择库而不是没有任何反应!
我正在使用Parse作为我的应用程序.我想查询一个表,其中列设置为指向其他表的指针.这是查询:
ParseQuery query = new ParseQuery("CategoryAttribute");
query.whereEqualTo("categoryId", categoryId);
query.findInBackground(new FindCallback() {
@Override
public void done(List<ParseObject> categoryAttributes, ParseException e) {
if (e == null) {
for (int i = 0; i < categoryAttributes.size(); i++){
String atributeCategoryId = categoryAttributes.get(i).getString("categoryId");
String attributeKey = categoryAttributes.get(i).getString("attributeKey");
String attributeValue = categoryAttributes.get(i).getString("attributeValue");
setCategoryAtributeRow(atributeCategoryId, attributeKey, attributeValue);
}
} else {
Log.d("score", "Error: " + e.getMessage());
}
}
});
Run Code Online (Sandbox Code Playgroud)
所以该categoryId
列是指向其他表的指针.其他列工作正常.我试图扫描API和指南,但找不到所需的解决方案.非常感谢帮助!
我试图在我的svg
强制布局(d3js)中创建碰撞检测.我已经按照本教程进行了圆形碰撞.
由于某种原因,它不适用于矩形.我试着在面纱中玩参数.
这是我的代码:
var node = svg.selectAll(".node")
.data(json.nodes)
.enter().append("g")
.attr("class", "node")
.call(force.drag);
node
.append("rect")
.attr("class", "tagHolder")
.attr("width", 60)
.attr("height", 60)
.attr("rx", 5)
.attr("ry", 5)
.attr("x", -10)
.attr("y", -10);
Run Code Online (Sandbox Code Playgroud)
还有这个:
svg.selectAll(".node")
.attr("x", function(d) { return d.x; })
.attr("y", function(d) { return d.y; });
link.attr("x1", function(d)
{
return d.source.x;
})
.attr("y1", function(d) { return d.source.y; })
.attr("x2", function(d) { return d.target.x; })
.attr("y2", function(d) { return d.target.y; });
node.attr("transform", function(d)
{
return "translate(" + d.x + "," + …
Run Code Online (Sandbox Code Playgroud) 我有这个简单的页面:
<!doctype html>
<html>
<head >
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href='bower_components/bootstrap/dist/css/bootstrap.css')>
<script src='bower_components/jquery/dist/jquery.min.js'></script>
<script src='bower_components/angular/angular.js'></script>
<script src='bower_components/bootstrap/dist/js/bootstrap.min.js'></script>
<script src='js/application.js'></script>
<title>Bets Application</title>
</head>
<body ng-app='betsApp' ng-controller='betsAppCtrl'>
<h1>BetsApp</h1>
<ng-view></ng-view>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
这是aplication.js
文件:
var betsApp = angular.module('betsApp', []);
betsApp.config(function($routeProvider, $locationProvider) {
$locationProvider.html5mode(true);
$routeProvider.when('/login', {templateUrl:'pages/login.html'});
});
betsApp.controller('betsAppCtrl', function($scope)
{
$scope.password = "";
$scope.email = "";
});
Run Code Online (Sandbox Code Playgroud)
这是login.html
:
<div>
<input type='text' ng-model='password' value={{password}}>
</div>
Run Code Online (Sandbox Code Playgroud)
运行时我在控制台中收到此错误:
Uncaught object angular.js:78
(anonymous function) angular.js:78
(anonymous function) angular.js:3809
forEach …
Run Code Online (Sandbox Code Playgroud)