但根据文档,它是一个服务器方法,我找不到如何调用此方法的示例。我试过了:
user = Meteor.call('Accounts.findUserByUsername', 'myUserName')
我得到了:
Error invoking Method 'Accounts.findUserByUsername': Method 'Accounts.findUserByUsername' not found [404]
答案 0 :(得分:2)
您需要创建服务器端方法,然后从客户端调用它。所以服务器端方法看起来像
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
<style name="FullscreenTheme" parent="AppTheme">
<item name="android:actionBarStyle">@style/FullscreenActionBarStyle</item>
<item name="android:windowActionBarOverlay">true</item>
<item name="android:windowBackground">@null</item>
<item name="metaButtonBarStyle">?android:attr/buttonBarStyle</item>
<item name="metaButtonBarButtonStyle">?android:attr/buttonBarButtonStyle</item>
</style>
<style name="FullscreenActionBarStyle" parent="Widget.AppCompat.ActionBar">
<item name="android:background">@color/black_overlay</item>
</style>
</resources>
然后在客户端,您将不得不通过调用调用该方法,并使用回调来处理来自服务器的响应
Meteor.methods({
find_by_username: function(name){
var user = Accounts.findUserByUsername(name));
return user;
}
});