我有一个带有停止按钮的无限循环的Javascript计时事件.
点击开始按钮时会显示数字.现在我想将这些数字转换为4小时3分50秒
var c = 0;
var t;
var timer_is_on = 0;
function timedCount() {
document.getElementById('txt').value = c;
c = c + 1;
t = setTimeout(function() {
timedCount()
}, 1000);
}
function doTimer() {
if (!timer_is_on) {
timer_is_on = 1;
timedCount();
}
}
function stopCount() {
clearTimeout(t);
timer_is_on = 0;
}
$(".start").on("click", function() {
//var start = $.now();
//alert(start);
//console.log(start);
doTimer();
$(".end").show();
$(".hide_div").show();
});
$(".end").on("click", function() {
stopCount();
});Run Code Online (Sandbox Code Playgroud)
.hide_div {
display: none;
}
.end {
display: none;
}Run Code Online (Sandbox Code Playgroud)
<script …Run Code Online (Sandbox Code Playgroud)我有一个城市和选民实体的一对多关系.我想将实体字段(下拉列表中的数千条记录)转换为文本输入,这样我就可以在用户开始输入2个字母时实现JQuery自动完成功能.两周,我成功创建了DataTransformer,它将实体字段转换为文本输入.现在我的问题是我还在学习JQuery/Ajax,我很困惑如何在Symfony2表单中实现它.
//formtype.php
private $entityManager;
public function __construct(ObjectManager $entityManager)
{
$this->entityManager = $entityManager;
}
$builder
->add('address', null, array(
'error_bubbling' => true
))
->add('city', 'text', array(
'label' => 'Type your city',
//'error_bubbling' => true,
'invalid_message' => 'That city you entered is not listed',
))
$builder->get('city')
->addModelTransformer(new CityAutocompleteTransformer($this->entityManager));
//datatransformer.php
class CityAutocompleteTransformer implements DataTransformerInterface
{
private $entityManager;
public function __construct(ObjectManager $entityManager)
{
$this->entityManager = $entityManager;
}
public function transform($city)
{
if (null === $city) {
return '';
}
return $city->getName();
}
public function reverseTransform($cityName) …Run Code Online (Sandbox Code Playgroud) 我想计算 Twig 中特定字段的总数
在 PHP 模板中,我可以很容易地做到这样
<?php $tl = 0; ?>
<?php foreach($loo as $l):>
<?php $tl += $l['amount'] ?>
<tr>
<td><?php echo $l['amount'] ?>
</tr>
<?php endforeach ?>
<p><?php echo number_format($tl,2) ?>
Run Code Online (Sandbox Code Playgroud)
如何在 Twig 中做到这一点?
我试过
{% set tl = 0 %}
{% for task in tasks %}
{% set tl += {{ task.amount }} %}
{% endfor %}
{{ tl }}
Run Code Online (Sandbox Code Playgroud)
它不起作用任何想法?
我有一个模型与一对多关系中的另外三个模型有多个关系.我以这种方式手动创建了一个Model类
class Voter < ActiveRecord::Base
belongs_to :city
belongs_to :grp
belongs_to :profession
end
Run Code Online (Sandbox Code Playgroud)
我有两个问题,
首先,如何创建具有多种关系的迁移?这是我的迁移文件
class CreateVoters < ActiveRecord::Migration
def change
create_table :voters do |t|
t.string :firstname
t.string :middlename
t.string :lastname
t.text :comments
t.date :birthday
t.references :city, index: true, foreign_key: true
t.timestamps null: false
end
end
end
Run Code Online (Sandbox Code Playgroud)
我想这样做
t.references :city, index: true, foreign_key: true
t.references :grp, index: true, foreign_key: true
t.references :profession, index: true, foreign_key: true
Run Code Online (Sandbox Code Playgroud)
这是对的吗?
第二个问题是,不是手动更改迁移文件,而是可以运行带有多个引用的"rails generate model"........以便在迁移文件中自动添加多个引用?如果可能,如何你做到了吗?
我在Windows 10机器中安装Java JDK,需要通过在Windows设置中编辑系统变量来注册其路径,但我尝试了作为管理员和普通用户,并且它不允许我添加路径,甚至复制粘贴或只是添加任何角色.我在Win 8中做到这一点都没有问题,直到我"试图"利用并运行微软的免费升级.
Q1:
这是Windows 10中的一个错误吗?我定期更新我的机器并打开自动更新以确保从Microsoft获得最新的修复程序.卡巴斯基也暂时被禁用.
Q2:
如何在Win 10机器中编辑系统变量?我打算将我的机器降级到Windows 7或8,如果这个问题没有解决的话.
有任何想法吗?
我是laravel的新手而且我仍然对Homestead.yaml的配置感到困惑
我的laravel项目位于C:/ wamp/www/laravel和Homestead.yaml我配置如下
folders:
- map: /wamp/www/laravel
to: /home/Vagrant/Code
sites:
- map: homestead.app
to: /home/Vagrant/Code/Laravel/public
databases:
- homestead
variables:
- key: APP_ENV
value: local
Run Code Online (Sandbox Code Playgroud)
这个配置有什么问题?我还需要手动创建
/home/Vagrant/Code
Run Code Online (Sandbox Code Playgroud)
和
/home/Vagrant/Code/Laravel/public?
Run Code Online (Sandbox Code Playgroud)
如果是的话,在哪个windows目录?我对/ home目录感到困惑,因为我使用的是Windows 8机器.
我正在创建一个用户表单,其中通过表单下拉列表选择角色.我的表单和实体看起来像这样
//entity
private $roles;
public function getRoles()
{
return $this->roles;
}
//form
class RoleType extends AbstractType
{
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults(array(
'choices' => array(
'ROLE_USER' => 'ROLE_USER',
'ROLE_ADMIN' => 'ROLE_ADMIN',
)
));
}
public function getParent()
{
return 'choice';
}
public function getName()
{
return 'role';
}
class RegistrationType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->add('username')
->add('password', 'repeated', array(
'type' => 'password',
'invalid_message' => 'The password fields must match.',
'options' => array('attr' => array('class' …Run Code Online (Sandbox Code Playgroud) 您如何将时间转换为整数?
string(8) "04:04:07"
Run Code Online (Sandbox Code Playgroud)
我希望这是4(小时)或更佳的4.04(4小时4分钟)
我试过了
$yourdatetime = "04:04:07";
$timestamp = strtotime($yourdatetime);
Run Code Online (Sandbox Code Playgroud)
导致
int(1458590887)
Run Code Online (Sandbox Code Playgroud)