如何id从调用插件的集合(而不是从DOM本身)中删除没有属性的元素?
<span id="id737293" class="attach"></span>
<div class="attach"></span>
Run Code Online (Sandbox Code Playgroud)
jQuery调用和插件:
$('.attach').attach();
(function($) {
$.fn.attach = function(options) {
// Remove elements (without id) on which the plugin was invoked
var valid = ???;
// Loop each valid element (with id attribute) and process
valid.each(function() {
});
return this; // Maintain chainability
};
})(jQuery);
Run Code Online (Sandbox Code Playgroud) 我不是很擅长MySQL,我打算写一个查询来计算用户发送的消息,根据它的类型和is_auto字段.
消息可以是"小文本消息"或"简报"类型.我创建了两个实体,它们之间有一些不同的字段.重要的是messages_count表中没有newsletter,它在查询中使用:
CREATE TABLE IF NOT EXISTS `small_text_message` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`messages_count` int(11) NOT NULL,
`username` varchar(255) NOT NULL,
`method` varchar(255) NOT NULL,
`content` longtext,
`sent_at` datetime DEFAULT NULL,
`status` varchar(255) NOT NULL,
`recipients_count` int(11) NOT NULL,
`customers_count` int(11) NOT NULL,
`sheduled_at` datetime DEFAULT NULL,
`sheduled_for` datetime DEFAULT NULL,
`is_auto` tinyint(1) NOT NULL,
`user_id` int(11) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB;
Run Code Online (Sandbox Code Playgroud)
和:
CREATE TABLE `newsletter` (
`id` …Run Code Online (Sandbox Code Playgroud) 我正在使用JMSSecurityExtra包来保护我的控制器中的方法.但有什么方法可以保护整个控制器@Secure?
表定义,注意UNIQUE索引:
CREATE TABLE meta
(
id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
type SET('tag', 'keyword') NOT NULL,
name VARCHAR(255) NOT NULL,
user_id INT UNSIGNED NOT NULL,
UNIQUE (name, type, user_id),
FOREIGN KEY (user_id) REFERENCES user (id) ON DELETE CASCADE
);
Run Code Online (Sandbox Code Playgroud)
所以MySQL应该WHERE name = 'tag' and type = 'cat'只在搜索中使用索引(仅限最左边的前缀)WHERE type = 'tag'.
我做了:
EXPLAIN SELECT * FROM meta WHERE type = 'tag'
Run Code Online (Sandbox Code Playgroud)
结果是(第五栏possible_keys):
'1', 'SIMPLE', 'meta', 'ALL', NULL, NULL, NULL, NULL, '1', 'Using where' …Run Code Online (Sandbox Code Playgroud) 使用Symfony中的文本字段类型,有一个修剪选项.我很确定该trim()操作是由Form\Extension\Core\EventListener\TrimListener班级进行的.它是该PRE_BIND事件的监听者并致电:
$event->setData(trim($event->getData()));
Run Code Online (Sandbox Code Playgroud)
我想提供自己的"normalize_spaces"选择:
$builder->add('last_name', 'text', array(
'label' => 'Last name',
'normlize_spaces' => true
));
Run Code Online (Sandbox Code Playgroud)
我怎样才能提供这个选项NormalizeSpacesListener?
class NormalizeSpacesListener implements EventSubscriberInterface
{
public function preBind(FormEvent $event)
{
$data = $event->getData();
if (is_string($data)) {
$event->setData(preg_replace('/[ ]{2,}/', ' ', $data));
}
}
public static function getSubscribedEvents()
{
return array(FormEvents::PRE_BIND => 'preBind');
}
}
Run Code Online (Sandbox Code Playgroud) 该schmittjoh/CG-库看来我需要什么,但没有文件可言.
该库提供了生成PHP代码通常需要的一些工具.其中一个优势在于通过行为增强现有类.
鉴于A课程:
class A {}
Run Code Online (Sandbox Code Playgroud)
我想在运行时和一些缓存机制上修改类A,使其实现给定的接口:
interface I
{
public function mustImplement();
}
Run Code Online (Sandbox Code Playgroud)
......与方法"默认"的实现mustImplement()在A类.
无法让我的Coffee脚本完全编译成:
( function (root) { return 'Hello Coffee'; }(this) );
Run Code Online (Sandbox Code Playgroud)
第一次尝试:
do (root) ->
'Hello Coffee'
Run Code Online (Sandbox Code Playgroud)
...没有生成与上面相同的代码,输出(with --bare):
(function(root) {
return 'Hello Coffee';
})(root);
Run Code Online (Sandbox Code Playgroud) 原型函数bar在Node.js环境中bind应该在别处执行(应该可用).我希望this内部bar()函数成为我的对象的实例:
var Foo = function (arg) {
this.arg = arg;
Foo.prototype.bar.bind(this);
};
Foo.prototype.bar = function () {
console.log(this); // Not my object!
console.log(this.arg); // ... thus this is undefined
}
var foo = new Foo();
module.execute('action', foo.bar); // foo.bar is the callback
Run Code Online (Sandbox Code Playgroud)
...为什么bar()日志undefined而this不是我的实例?为什么bind调用不会改变执行上下文?
async.map(['file1','file2','file3'], fs.stat, function(err, results){
// results is now an array of stats for each file
});
Run Code Online (Sandbox Code Playgroud)
根据文档,第二个参数是:
iterator(item,callback) - 一个应用于数组中每个项的函数.
精细.
迭代器传递一个回调(错误,转换),一旦完成错误(可以为null)和转换项,就必须调用它.
我认为这fs.stat不符合这一点,我会说这不应该奏效.
它应该是这样的:
async.map(['file1','file2','file3'],
function (file, complete) {
fs.stat(file, function (err, stat) {
complete(err, stat)
});
}, function(err, results){
// results is now an array of stats for each file
}
);
Run Code Online (Sandbox Code Playgroud) 从来没有遇到过这个问题.
Default和Create)$phone字段上,而应该是mappend到$lastName自己的属性
你能重现同样的问题吗?
$phone属性在Create验证组中,而Default隐藏组中的$ phone :
class User
{
/**
* @Assert\NotBlank(groups={"Create"}, message="Last name is required.")
*
* @var string
*/
protected $lastName;
/**
* @Assert\NotBlank(message="Phone is required.")
*
* @var string
*/
protected $phone;
}
Run Code Online (Sandbox Code Playgroud)
我根据提交的数据确定验证组:
class UserType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->add('lastName', 'text');
$builder->add('phone', 'text');
$builder->add('submit', 'submit');
}
public function setDefaultOptions(OptionsResolverInterface $resolver)
{
$resolver->setDefaults([
'required' => false, …Run Code Online (Sandbox Code Playgroud) symfony ×3
mysql ×2
node.js ×2
php ×2
asynchronous ×1
coffeescript ×1
indexing ×1
javascript ×1
jms ×1
jquery ×1
node-async ×1
optimization ×1
php-5.3 ×1
runtime ×1
sql ×1
symfony-2.4 ×1
this ×1