给定一组在一个字段中具有给定值的文档,我想知道有多少文档具有第二个字段的每个值.
我尝试使用以下查询的术语聚合来做到这一点:
{
"size": 0,
"filter": {
"term": {
"field1": "value"
}
},
"aggregations": {
"field2" : {
"terms" : { "field" : "field2" }
}
}
}
Run Code Online (Sandbox Code Playgroud)
但返回的计数显示整个索引中第二个字段的每个值的文档数,而不限于第一个字段具有给定值的文档.
我究竟做错了什么?
我一直无法让WebStorm 11识别/突出显示/解析ES6/ES2015 javascript,当它在常规HTML中的脚本标记内时.找不到似乎适用于此的设置.在此先感谢您的时间.
例如,以下js位于脚本标记内.你会注意到WebStorm认为一大堆东西都被破坏了,但它执行得很好.
javascript syntax-highlighting jetbrains-ide webstorm ecmascript-6
我想获得value conventer的结果,在我的视图中过滤一个数组,以显示找到的结果数.
<div repeat.for="d of documents|docfilter:query:categories">
<doc-template d.bind="d"></doc-template>
</div>
Run Code Online (Sandbox Code Playgroud)
我既不想将这个逻辑移动到我的控制器(保持干净),也不想添加拐点,比如从值控制器返回一些数据.
所以,基本上我想是这样的角度报价:像显示在这里:
ng-repeat="item in filteredItems = (items | filter:keyword)"
或这里:ng-repeat="item in items | filter:keyword as filteredItems"
不幸的是,在Aurelia:
d of filteredDocuments = documents|docfilter:query:categories
实际上意味着d of
filteredDocuments =文件 |docfilter:query:categories
,如果我添加括号as
,它将无法运行(失败并出现解析器错误).
是否有一种干净的方式从数据过滤器中获取数据?
此致,亚历山大
export class DocfilterValueConverter {
toView(docs, query, categories, objectToPassCount) {
...
objectToPassCount.count = result.length;
...
});
});
Run Code Online (Sandbox Code Playgroud)
d of
filteredDocuments = documents |docfilter:query:categories
.它没有解决问题,但这段代码的作用是:1) …
我正在用Aurelia开发一个应用程序,让我说我有一个循环:
<div repeat.for="t of allTags">${t.name}</div>
Run Code Online (Sandbox Code Playgroud)
有很多条目,我很自然地想限制它们的数量.所以基本上我想要像Angular的重复限制:
<div ng-repeat="t in allTags | limitTo:5 ">{{t.name}}</div>
Run Code Online (Sandbox Code Playgroud)
我在这里检查了文档http://aurelia.io/docs.html但没有找到关于该主题的任何内容.
在Aurelia有这样的功能吗?如果不是,我宁愿在控制器中剪切列表$index
吗?
谢谢!
据我所知,Aurelia不支持这里提到的服务器端渲染.
但问题是:是否有可能通过一些黑客/解决方法来做到这一点?
最明显的想法是使用Phantom,Nightmare.js或其他任何东西来简单地在服务器上的Chrome中呈现该页面并将其提供给客户端,但这很可能会导致很大的生产力问题.
谢谢!
根据Rob Eisenberg今天(2016年4月16日)对FDConf的回应,服务器端渲染将在2016年实施,有一个核心团队成员正在研究这个,并且这个功能有截止日期.
我们已升级Aurelia大街(特别aurelia-framework
到1.0.6
,aurelia-bindong
到1.0.3
),现在我们正面临着一些绑定问题.
有一个带有计算类的元素列表,我们在包含列表的自定义元素中有一个方法:
getClass(t) {
return '...' +
(this.selected.indexOf(t) !== -1
? 'disabled-option' :
: ''
) + (t === this.currentTag
? 'selected-option'
: ''
);
}
Run Code Online (Sandbox Code Playgroud)
而class.one-way="$parent.getClass(t)"
对于列表元素,一切OK.
在升级之后,它只是停止工作,因此每当selected
(btw它的可绑定)或currentTag
属性被修改时,该getClass
方法就不会被调用.
我通过将此逻辑移动到视图来部分解决了这个问题:
class="${$parent.getClass(t) + (selected.indexOf(t) !== -1 ? 'disabled-option' : '') (t === $parent.currentTag ? 'selected-option' : '')}"
Run Code Online (Sandbox Code Playgroud)
我知道看起来很好......但是这样做了t === $parent.currentTag
,但是这个disabled-option
课仍然没有应用.
所以,问题是:
我知道它可能会导致一些性能问题.
我不能简单地selected
向list元素添加一个属性,因为我不会以某种方式修改自定义元素的数据,我基本上希望我的代码能够正常工作而不需要做太多更改.
我正在尝试构建一个网站,当用户向上或向下滚动页面时,该网站会自动滚动到每个部分.我已经试图解决这个问题好几个星期,并希望对此事有任何帮助.我相信问题是因为事件处理程序是一个滚动事件,它触发一个滚动函数,这会导致多个滚动发生.我已经阅读了很多讨论这个主题的文章,解决方案似乎是添加了一个setInterval或setTimeout函数,但是我已经尝试了两个并且仍然没有结果.
var page = $("#page_container");
var home = $("#home");
var musicians = $("#musicians");
var athletes = $("#athletes");
var politics = $("#politics");
var bio = $("#bio");
var pages = [home, musicians, athletes, politics, bio];
var scrolled = false;
var pageCur = 0;
var lastScrollTop = 0;
page.scroll(function () {
scrolled = true;
});
var scrollTimeout = setInterval(function () {
if (scrolled == true) {
pageScroll();
}
else {
clearTimeout(scrollTimeout);
}
}, 3000);
function pageScroll() {
if (scrolled == true) {
scrolled …
Run Code Online (Sandbox Code Playgroud) 我有客户页面和ajax我加载他们是否向我们发送电子邮件的信息.
代码如下所示:
$hostname = '{imap.gmail.com:993/imap/ssl}INBOX';
$username = 'email';
$password = 'password';
$this->session->data['imap_inbox'] = $inbox = imap_open($hostname,$username,$password) or die('Cannot connect to Gmail: ' . imap_last_error());
foreach($customers as $customer){
$emails = imap_search($inbox, 'FROM ' . $email);
// Processing info
}
Run Code Online (Sandbox Code Playgroud)
但是在一个页面上大约有20-30个客户,因此该过程有时需要大约10-20秒才能显示,我无法优化该过程.
但是当客户端尝试重新加载页面时,它仍然在imap_search
完成之前等待,因此在重新加载时可能需要20秒才能实际重新加载页面.
我试图中止ajax
with beforeunload
函数并关闭imap
但是这不起作用.
我的代码:
阿贾克斯:
$(window).bind('beforeunload',function(){
imap_email.abort(); // the ajax is succesfully aborted(as showed in console), yet the page still takes considerable time to reload
$.ajax({
type: 'GET',
url: 'getimapmails&kill=1',
async:false
}); // ajax …
Run Code Online (Sandbox Code Playgroud) 我想将焦点设置为表单元素.使用jQuery,这非常简单$('selector').focus
.
我创建了一个简单的<input ref="xxx" id="xxx" type="text">
在我的.ts文件中添加一个属性并在此处使用它:
attached() {
this.xxx.focus()
}
Run Code Online (Sandbox Code Playgroud)
什么都没发生.开始觉得一些简单的事情变得越来越困难,我肯定从来都不是重点.
(原始用例是在显示折叠时将焦点设置为Bootstrap折叠中的表单元素,如下所示:
// set focus to the first element when the add-cell collapse is shown
$('#collapsedAddTask').on('shown.bs.collapse', function () {
$('#AddTaskTitle').focus()
})
Run Code Online (Sandbox Code Playgroud)
这适用于我的基本HTML(不是单页应用程序),但不适用于Aurelia.Aurelia的方式是什么?
更新 使用下面的Miroslav Popovic的答案,并在评论中,我得到了它的工作(记住,这是一个Bootstrap崩溃组件):
<!-- the heading with an A that toggles visibility -->
<div class="panel-heading">
<a href="#collapsedAddTask" data-toggle="collapse" id="addTaskHeader" click.delegate="addTaskShown()">Add task</a>
</div>
<!-- the body, which is initially hidden -->
<div class="panel-body">
<div class="collapse" id="collapsedAddCell">
<input type="text" focus.bind="addTaskFocused">
<!-- more controls ... --> …
Run Code Online (Sandbox Code Playgroud) 我在React/Redux应用程序上收到此错误消息,该应用程序已缩小并与Browserify和Gulp一起打包并部署到Heroku.
bundle.js:39 You are currently using minified code outside of NODE_ENV === 'production'. This means that you are running a slower development build of Redux.
但似乎构建步骤正在进行中NODE_ENV = 'production'
.
我有一个设置env变量的任务
gulp.task('apply-prod-environment', function() {
return process.env.NODE_ENV = 'production';
});
Run Code Online (Sandbox Code Playgroud)
Heroku上的日志显示ENV正在生产:
为了保证在apply-prod-environment
其他任务之前运行,我正在使用RunSequence
Gulp插件.
gulp.task('buildProd', cb => {
runSequence(
'apply-prod-environment',
'task-1',
'task-2',
'etc',
cb
);
});
Run Code Online (Sandbox Code Playgroud)
编辑
第二次尝试..
import envify from 'envify/custom';
function buildJS(sourceFile, {setEnv}) {
return browserify(sourceFile)
.transform(babelify, {
presets: ['es2015', 'react', 'stage-2']
})
.transform(envify({
NODE_ENV: setEnv
})) …
Run Code Online (Sandbox Code Playgroud) 我有以下简单的映射:
"element": {
"dynamic": "false",
"properties": {
"id": { "type": "string", "index": "not_analyzed" },
"group": { "type": "string", "index": "not_analyzed" },
"type": { "type": "string", "index": "not_analyzed" }
}
}
Run Code Online (Sandbox Code Playgroud)
基本上,这是一种存储Group
对象的方法:
{
id : "...",
elements : [
{id: "...", type: "..."},
...
{id: "...", type: "..."}
]
}
Run Code Online (Sandbox Code Playgroud)
我想找到多少个不同的组,它们共享同一组元素类型(有序的,包括重复的)。
一个明显的解决方案是将架构更改为:
"element": {
"dynamic": "false",
"properties": {
"group": { "type": "string", "index": "not_analyzed" },
"concatenated_list_of_types": { "type": "string", "index": "not_analyzed" }
}
}
Run Code Online (Sandbox Code Playgroud)
但是,由于要求,我们需要能够从(聚合)分组中排除某些类型:(
该文档的所有字段都是mongo id,因此在SQL中,我将执行以下操作:
SELECT COUNT(id), …
Run Code Online (Sandbox Code Playgroud) javascript ×9
aurelia ×5
jquery ×3
aggregation ×2
ajax ×1
browserify ×1
concat ×1
css ×1
dom ×1
ecmascript-6 ×1
filter ×1
gulp ×1
html ×1
imap ×1
php ×1
reactjs ×1
redux ×1
webstorm ×1