我确定这必须存在于某个地方,但我一直无法找到它......
我正在尝试编写一个将对象作为参数并更新其引用的函数.不是引用的属性,也不是重新分配对象,而是更新整个引用.
请注意,PubSub只是为了证明在传入和更新的对象类型中需要异步性和灵活性.
最好用例子解释:
//ideally how function would work
function watch(event, obj) {
PubSub.on(event, function(model) {
// I want to update the entire object
// I understand that currently, this is just reassigning
// I know I can do obj.prop = model, but that's not what I want to do
obj = model;
}
};
//example usage
var myObj = {"name" : "Tom"};
watch("anEvent", myObj);
console.log(myObj.name); //still "Tom"
// time passes, then somewhere
PubSub.trigger("anEvent", {"name" : "John"})
console.log(myObj.name); // now …Run Code Online (Sandbox Code Playgroud) 我有几个自定义标签的HTML.我想找到除了两个之外的所有('开始','结束')并打开它们.当我搜索文档中的内容时,jQuery.find()似乎只找到这些自定义标记,而不是在搜索jQuery对象时.我究竟做错了什么?
在小提琴中应该是不言自明的:
这是javascript部分:
var raw = $('pre').html();
var html = $(raw);
var starts = html.find('start');
var spans = html.find('span');
//this returns nothing
console.log(starts)
// works - can find in object
console.log(spans)
//this works
console.log($('start'));
//only picks up spans, not annotations
// I want this to return the innerHTML of the pre, stripping all tags except for 'start' and 'end' -- but retain the contents of those tags.
var cleaned = html.find(':not(start, end)').each(function() {
$(this).contents().unwrap();
});
console.log(cleaned);
$('#clean').html(cleaned)
Run Code Online (Sandbox Code Playgroud)
和HTML的一个例子:
<span …Run Code Online (Sandbox Code Playgroud) mongod如果服务器尚未运行,我想编写一个grunt任务来启动进程.我需要运行一个mongod进程,但是还需要grunt-watch在以后的任务流程中工作.
这个问题解释了如何启动mongod使用grunt-shell...接受的答案是阻止,并且异步版本将生成一个新的服务器,即使存在.
是否有一种方法(例如shell脚本)只有在没有运行的情况下启动mongod,而不会阻止其余的grunt任务流?
谢谢
可能重复:
如何在PHP中将ereg表达式转换为preg?
我正在研究PHP脚本.
我有一个表格的网址:
http://ecx.images-amazon.com/images/I/5104Xl51zFL._SL175_.jpg
我只是想抓住文件名的第一部分5104Xl51zFL.
我对regexp很新,但到目前为止,我有:
.*images\/I\/(.+?)(\.[^.]*|$)
Run Code Online (Sandbox Code Playgroud)
根据regextester.com应该可以工作但不在我的PHP中.
如果它不是最佳解决方案,则不必是正则表达式.
如果这是相关的,那么我的PHP(仍然是调试):
function linkExtractor($html)
{
if(preg_match_all('/<img ([^>]* )?src=[\"\']([^\"\']*\._SL175_\.jpe?g)[\"\']/Ui', $html, $matches, PREG_SET_ORDER)){
foreach ($matches as $match) {
$url = $match[2];
echo "\n\n" .$url . "\nfile name: ";
if(preg_match_all('.*images\/I\/(.+?)(\.[^.]*|$)', $url, $matched, PREG_SET_ORDER)) {
foreach($matched as $name) {
print_r($matched);
}
}
}
}
}
Run Code Online (Sandbox Code Playgroud)