我试图找出如何获取存储在我们数据库中的两个日期时间字符串,并将其转换为时间格式hh:mm:ss的差异.
我看了看diffForHumans
,但是这确实给我想要的格式,并返回之类的东西after
,ago
等; 这很有用,但不适合我想要做的事情.
持续时间永远不会超过几天,最多只有几个小时.
$startTime = Carbon::parse($this->start_time);
$finishTime = Carbon::parse($this->finish_time);
$totalDuration = $finishTime->diffForHumans($startTime);
dd($totalDuration);
// Have: "21 seconds after"
// Want: 00:00:21
Run Code Online (Sandbox Code Playgroud) SCENERIO用户有一个下拉列表,他选择了一个选项.我想显示该下拉列表并将该选项设置为上次由该用户选择的默认值.
我在选项上使用了选定的属性,但React会生成一个警告,要求我在select上使用默认值.
例如
render: function() {
let option_id = [0, 1];
let options = [{name: 'a'}, {name: 'b'}];
let selectedOptionId = 0
return (
<select defaultValue={selectedOptionId}>
{option_id.map(id =>
<option key={id} value={id}>{options[id].name}</option>
)}
</select>
)
}
});
Run Code Online (Sandbox Code Playgroud)
问题是我不知道selectedOptionId,因为所选的选项可以是任何选项.我怎样才能找到defaultValue?
我正在尝试运行迁移(见下文)并为数据库播种,但是当我运行时
php artisan migrate --seed
Run Code Online (Sandbox Code Playgroud)
我收到此错误:
Migration table created successfully.
Migrated: 2015_06_17_100000_create_users_table
Migrated: 2015_06_17_200000_create_password_resets_table
Migrated: 2015_06_17_300000_create_vehicles_table
[Illuminate\Database\QueryException]
SQLSTATE[42000]: Syntax error or access violation: 1701 Cannot truncate a table
referenced in a foreign key constraint (`app`.`vehicles`, CONSTRAINT `vehic
les_user_id_foreign` FOREIGN KEY (`user_id`) REFERENCES `app`.`users` (`id`
)) (SQL: truncate `users`)
[PDOException]
SQLSTATE[42000]: Syntax error or access violation: 1701 Cannot truncate a table
referenced in a foreign key constraint (`app`.`vehicles`, CONSTRAINT `vehic
les_user_id_foreign` FOREIGN KEY (`user_id`) REFERENCES `app`.`users` (`id`
))
Run Code Online (Sandbox Code Playgroud)
我查看了这个错误应该是什么意思,并且还找到了遇到同样问题的其他人的 …
我正在尝试从scripts.postinstall的grunt运行多个CLI命令.我无法弄清楚如何让两者都运行.如果我添加第二个命令既不运行.另外,他们都在postinstall和控制台上工作.
我已经尝试将它们包装在一个数组中:
"scripts": {
"postinstall": ["node_modules/.bin/bower install", "grunt setup"]
},
Run Code Online (Sandbox Code Playgroud)
我尝试用分号分隔它们:
"scripts": {
"postinstall": "node_modules/.bin/bower install; grunt setup"
},
Run Code Online (Sandbox Code Playgroud)
我似乎无法在NPM Scripts上找到解决方案
我对这些部分的gruntfile.js看起来像这样:
mkdir: {
setup: {
options: {
create: [
'app/main/source/www', 'app/main/build', 'app/main/docs', 'app/main/tests',
'app/development',
'app/releases'
]
}
}
}
grunt.registerTask('setup', [
'mkdir:setup',
'bowercopy:wordpress'
]);
Run Code Online (Sandbox Code Playgroud)
如果它有助于我的package.json的parred down版本,我剪切了上面的代码示例,主要是为了提供上下文.
{
"name": "webapp",
"version": "0.1.0",
"description": "A web app using bower and grunt",
"main": "gruntfile.js",
"scripts": {
"postinstall": "node_modules/.bin/bower install"
},
"repository": {
"type": "git",
"url": "someurl.com"
},
"keywords": [
"web", …
Run Code Online (Sandbox Code Playgroud) 如何通过当前的$ routeParams来解析,以便它们可用于执行特定的$ http.get.现在我刚刚测试了$ routeParams并传回了param以登录我的控制器以查看它是否有效,但它是每次后面的路线.例如,在加载时它是未定义的,并且在后续路由上,param是先前的路由参数,因此我单击一个新链接并显示前一个链接路由的参数.
路线片段
.when('/something/:paramType', {
templateUrl: '/app/views/something.html',
controller: 'SomethingController',
controllerAs: 'someCtrl',
access: {
authentication: true
},
resolve: {
SomeData: function( $routeParams ) {
return $routeParams.paramType;
}
}
})
Run Code Online (Sandbox Code Playgroud)
控制器片段
.controller('SomethingController', ['$scope', 'SomeData', function( $scope, SomeData) {
console.log(SomeData);
}])
Run Code Online (Sandbox Code Playgroud)
如何在加载时初始化参数,并使其每次都正确同步?我想这样做的原因是我可以执行$ http.get并传递$ routeParams来定义返回的数据.
刚刚开始使用Sequelize,我已经设置了一堆模型和种子,但我无法弄清楚引用与关联.如果他们甚至做了我认为他们做的事情,我没有看到引用的用例,但我在文档中找不到好的解释.
这是多余的引用和关联?
module.exports = (sequelize, DataTypes) => {
const UserTask = sequelize.define('UserTask',
{
id: {
primaryKey: true,
type: DataTypes.UUID,
defaultValue: DataTypes.UUIDV4
},
userId: {
type: DataTypes.UUID,
references: { // <--- is this redundant to associate
model: 'User',
key: 'id'
}
}
// ... removed for brevity
},
{
classMethods: {
associate: models => { <--- makes references redundant?
UserTask.belongsTo(models.User, {
onDelete: 'CASCADE',
foreignKey: {
fieldName: 'userId',
allowNull: true,
require: true
},
targetKey: 'id'
});
}
}
}
);
return UserTask; …
Run Code Online (Sandbox Code Playgroud) 我在使用角度4的路径时遇到了一些问题.您知道,当我尝试将数据从组件传递到另一个组件时navigate('root', data)
,我刚接收到[object Object],[object Object],[object Object]
.
零件
export class FillRequestComponent implements OnInit {
constructor(private route: Router, private dataRoute: ActivatedRoute) { }
ngOnInit() {
const key: Products = this.dataRoute.snapshot.params['objectProducts'];
console.log(key);
}
Run Code Online (Sandbox Code Playgroud)
接口
export interface Products {
color: string,
question: string,
surname: string,
icon: string,
selected: boolean,
transparent: boolean
}
Run Code Online (Sandbox Code Playgroud)
发送方法
const data = {
category: this.optionSelected,
objectProducts: this.optionSelected === 'CREDIT' ? this.productCreditList :
this.productAccountsList
};
this.route.navigate(['/requests/fill', data]);
Run Code Online (Sandbox Code Playgroud) 我只是想制作一些片段,但我不能让它们中的任何一个工作.有人能看出这有什么问题吗?我阅读了他们的文档,并在网上翻阅了一些例子,但它们也没有用.我已经在我的/sublime text 3/packages/user
文件夹中找到它并使用约定命名myTest.sublime.snippet
.
该片段是:
<snippet>
<content>
<![CDATA[
<!DOCTYPE html lang="en">
<!--[if lt IE 7]><html class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]-->
<!--[if IE 7]><html class="no-js lt-ie9 lt-ie8"> <![endif]-->
<!--[if IE 8]><html class="no-js lt-ie9"> <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js"> <!--<![endif]-->
<head>
<meta charset="utf-8">
<title>${1:test1|test2|test3} | $2</title>
<meta name="viewport" content="width=device-width">
<meta name="Description" lang="en" content="Description">
<meta name="robots" content="index, follow">
<meta name="robots" content="noodp, noydir">
<!-- Twitter Bootstrap -->
<link href="//netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css" rel="stylesheet">
<link href="//netdna.bootstrapcdn.com/font-awesome/3.2.1/css/font-awesome.min.css" rel="stylesheet">
<script src="//netdna.bootstrapcdn.com/bootstrap/3.0.0/js/bootstrap.min.js"></script>
<!--[if lt IE 9]> …
Run Code Online (Sandbox Code Playgroud) 我一直在玩UI-Router,因为根据我需要多个嵌套视图的不同布局,ngRoute并没有完全涵盖我需要的东西.我在UI-Router中无法弄清楚的是如何在不必点击链接的情况下加载默认的嵌套视图.我创造了一个粗略的例子,说明我在一个傻瓜中的意思
基本上每个主要路径有两个主机,它有一个容纳嵌套视图的容器.我想在其中加载默认视图而无需单击ui-sref.
<h1>Auth Panel</h1> <-- main route 1
Just a container for login/forgot/reset
<hr/>
<a ui-sref="auth.login">Show Login</a><br> <-- can click to load nested view, but want to autoload
How to show automatically /login within the panel <br>
without having to click show login?
<div ui-view></div> <-- child to autoload with /login
Run Code Online (Sandbox Code Playgroud)
谢谢
我试图使用我在这里找到的这个例子在第一页上隐藏页眉页码.只有当我使用footer-html并且如果我将它与header-html一起使用时,它才会显示/隐藏任何内容.最初我试图增加这个解决方案这也使用footer-html工作,但由于我不能让它在标题中工作,我继续搜索.我已经尝试了有没有'header-center'=>'[[page]]',以防万一使用header-html导致冲突.最近有人能够在标题中使用它吗?我正在使用PHPWKHTMLtoPDF包装器版本1.2.6-dev,如果这有助于WKHTMLtoPDF的最新版本,因为最新版本的PHPWKHTMLtoPDF使用名称空间,我们正在使用CodeIgniter 2.x-dev,它不支持它们(或打得好不能记住).
// Create document PDF
$pdf = new $this->wkhtmltopdf;
// Locate WkHtmlToPdf executable for Windows
if( $pdf->getIsWindows() )
{
$pdf->setOptions( array( 'binPath' => 'C:\Program Files\wkhtmltopdf\bin\wkhtmltopdf.exe',
'no-outline',
'encoding' => 'UTF-8',
'margin-top' => 30,
'margin-right' => 20,
'margin-bottom' => 30,
'margin-left' => 20,
// Default page options
'disable-smart-shrinking',
'user-style-sheet' => 'pdf.css',
'header-html' => dirname(__FILE__) . '\..\views\wkhtmltopdf\header.html'
) );
}
// Generate document fields
$docInputs = $this->generate_inputs( $inputs, json_decode( $this->load->file( APPPATH . '/mapping/' . $document['mapping'], TRUE ), TRUE …
Run Code Online (Sandbox Code Playgroud) angularjs ×2
javascript ×2
laravel ×2
angular ×1
bower ×1
date ×1
dropdown ×1
gruntjs ×1
laravel-5 ×1
laravel-5.1 ×1
mysql ×1
node.js ×1
php ×1
php-carbon ×1
reactjs ×1
select ×1
sequelize.js ×1
sublimetext3 ×1
typescript ×1
wkhtmltopdf ×1