我有一个系列Feeds和一个系列FeedElements.FeedElements文档Feeds通过feedId字段引用该集合.此外,所有FeedElements文档都有日期字段submitted.
我想只发布最新的(由字段确定submitted)FeedElements文档,该文档对应于一个Feeds文档.
这是我尝试过的:
Meteor.publish('recentFeedElements', function (userId) {
var feedIds = Feeds.find({'userId': userId}).map(function(feed) {
return feed._id;
});
if (feedsIds.length > 0) return FeedElements.find({feedId: {$in: feedIds}}, {sort: {submitted: -1});
else this.ready();
});
Run Code Online (Sandbox Code Playgroud)
问题是,如果我用limit结合sort的内部FeedElements.find()查询,我只得到所有的最新文档Feed文件.但是,我希望有一个严格的1-1关系.所以,一个Feed文件 - >最新的FeedElements文件与适当的参考.
我有以下父模板:
<template name="parentTempl">
{{#each child}}
{{> childTempl}}
{{/each}}
</template>
Run Code Online (Sandbox Code Playgroud)
我想访问父数据上下文childTempl:
Template.childTempl.rendered = function() {
console.log(this.parent.data); // ?
};
Run Code Online (Sandbox Code Playgroud)
我怎样才能做到这一点?任何帮助将不胜感激.
我想MainActivity在我的Android应用程序中测试我的.因此,我创建了第一个测试按钮功能的测试用例.如果用户单击此特定按钮,则应打开一个新活动.
这是我的代码:
@RunWith(AndroidJUnit4.class)
public class MainActivityTest {
@Rule
public ActivityTestRule<MainActivity> mActivityRule = new ActivityTestRule<>(MainActivity.class);
@Test
public void startNewActivityTest() {
Intents.init();
onView(withId(R.id.main_new)).perform(click());
intended(hasComponent(NewActivity.class.getName()));
Intents.release();
}
@Before
public void setup() {
closeSoftKeyboard();
}
}
Run Code Online (Sandbox Code Playgroud)
不幸的是,我得到以下异常:
junit.framework.AssertionFailedError: No tests found in package.MainActivityTest
at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:191)
at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:176)
at android.test.InstrumentationTestRunner.onStart(InstrumentationTestRunner.java:554)
at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1701)
Run Code Online (Sandbox Code Playgroud)
这是我的Gradle文件:
apply plugin: 'com.android.application'
android {
compileSdkVersion 19
buildToolsVersion "23.0.1"
lintOptions {
abortOnError false
}
defaultConfig {
applicationId "package"
minSdkVersion 14
targetSdkVersion 19
}
signingConfigs {
debug {
storeFile file(RELEASE_STORE_FILE)
storePassword …Run Code Online (Sandbox Code Playgroud) 我升级到Meteor 1.0,安装了最新的铁路由器包,尝试运行我的应用程序并在我的控制台日志中得到了这个好警告:
路线调度从未呈现.你忘了在onBeforeAction中调用this.next()吗?
所以我尝试根据新版本修改我的路线.
this.route('gamePage', {
path: '/game/:slug/',
onBeforeAction: [function() {
this.subscribe('singlePlayer', this.params.slug).wait();
var singlePlayer = this.data();
if (singlePlayer) {
if (singlePlayer.upgrade) {
this.subscribe('upgrades', this.params.slug).wait();
this.next();
}
this.next();
}
this.next();
}],
data: function() {
return Games.findOne({slug: this.params.slug});
},
waitOn: function() { return [Meteor.subscribe('singleGame', this.params.slug)]}
});
Run Code Online (Sandbox Code Playgroud)
我怎样才能解决这个问题?任何帮助将不胜感激.
我想在我的AngularJS应用程序中使用CryptoJS,但是我收到了这个错误:Can't find variable: CryptoJS.
我把它包括在我的index.html:
<script src="http://crypto-js.googlecode.com/svn/tags/3.1.2/build/rollups/rc4.js"></script>
Run Code Online (Sandbox Code Playgroud)
并试图加密一些东西:
var encrypted = CryptoJS.RC4Drop.encrypt("Message", "Secret Passphrase");
Run Code Online (Sandbox Code Playgroud)
任何帮助将不胜感激.
我正在尝试通过单击引导程序弹出窗口中的按钮来触发流星事件.但是,事件并没有被解雇.
这是我的代码:
<button name="newLetter" class="glyphicon glyphicon-plus newLetter" type="button" data-container="body" data-toggle="popover" data-placement="right"></button>
<div id="popover-content" class="hide">
<textarea></textarea>
<button class='glyphicon glyphicon-ok btn btn-success btn-xs addNewLetter'></button>
</div>
Run Code Online (Sandbox Code Playgroud)
Template.templateName.events({
'click .newLetter': function(e, t) {
$(".newLetter").popover({
html: true,
title: 'New Letter',
content: function() {
return $("#popover-content").html();
}
});
},
'click .addNewLetter': function(e, t) {
console.log('test');
}
});
Run Code Online (Sandbox Code Playgroud)
任何帮助将不胜感激.
是否可以在Spacebars中使用逻辑运算符(没有模板助手)?
例如:
{{#if status == '0'}}
Hello world.
{{/if}}
Run Code Online (Sandbox Code Playgroud)
不幸的是,我收到以下错误:
While processing files with templating (for target web.browser):
client/views/test.html:46: Expected identifier, number, string, boolean, null, or a sub expression enclosed in "(", ")"
... {{#if status == '0'}} ...
^
=> Your application has errors. Waiting for file change.
Run Code Online (Sandbox Code Playgroud) 有没有比这“更好”的方法来检查对象是否具有空数组(0-*):
\n\nemptyArr: function() {\n var obj = getObj();\n return obj.abc.length == 0 || obj.def.length == 0 || obj.ghi.length == 0 || obj.jkl.length == 0 \xe2\x80\xa6\xe2\x80\xa6\xe2\x80\xa6\xe2\x80\xa6;\n}\nRun Code Online (Sandbox Code Playgroud)\n\n编辑:\n该对象如下所示:
\n\n- Object\n - abc = []\n - def = []\n - ghi = []\n - jkl = []\n - \xe2\x80\xa6\nRun Code Online (Sandbox Code Playgroud)\n\n我想检查该对象是否包含任何空数组。
\n\n任何帮助将不胜感激。
\n目前,我以这样的方式保存日期:ISODate("2014-11-17T16:19:16.224Z"),但我想要这样的结果:ISODate("2014-11-16T23:00:00Z")。我怎样才能做到这一点?
我尝试使用最新日期获取文档,但是我收到此错误:TypeError: 'undefined' is not a function.
我的代码:
console.log(Games.find({authorId: authorId}).sort( { releaseDate: -1 } ).limit(1)); // error
console.log(Games.find({authorId: authorId}).fetch()); // expected outpout
Run Code Online (Sandbox Code Playgroud)
(该值releaseDate存在且ISODate格式正确.)任何帮助将不胜感激.
编辑:我正在使用Meteor 0.9.2.1.
有没有办法像这样转换数组:
"team" : [ { "player" : "John", "rank" : 0 }, { "player" : "Peter", "rank" : 2 } ]
Run Code Online (Sandbox Code Playgroud)
对此:
"team" : [ "John", "Peter" ]
Run Code Online (Sandbox Code Playgroud)
使用Underscore.js或jQuery?
任何帮助将不胜感激.
javascript ×9
meteor ×6
jquery ×3
arrays ×2
mongodb ×2
android ×1
angularjs ×1
cryptojs ×1
encryption ×1
iron-router ×1
java ×1
junit ×1
spacebars ×1