小学校! しかし、彼らが以前に同様の指示を私に見せたら...
タスク
キーのないリクエスト
/プロファイルで 、ユーザーが「間違っている」場合は
ログインテンプレートを提供し、そうでない場合は、
newProfileを追加するか、
プロファイルのプロファイル (editMode)を編集するテンプレートを提供します。 また、リクエスト
/プロファイル/キーに応じて、任意のプロファイルの
プロファイル (editModeではない)を表示するテンプレートを提供します。 同時に、userIdは点灯せず、無効なキーは
invalidProfileで拒否され
ます 。
[
ソース ]
解決策
コレクションを作成してい
ます 。
@Collections.Profiles = new Mongo.Collection('profiles')
ルーターマップ(パス名)。
Router.route '/profile/:_id?', name: 'profile'
ルーターを作成し
ます 。
@ProfileController = RouteController.extend
必要なデータを持つ変数(2つのルーター方式間の転送に必要)。
profile: null
ルータは発表された
サブスクリプションを期待し
ます 。
waitOn: ->
魔法は
反応性です。
if Meteor.loggingIn()
URLにパラメーターがある場合は、サブスクライブしてコレクションを表示します。
else if @params._id return Meteor.subscribe 'profile4view', @params._id
それ以外の場合、ユーザーがログインしている場合は、コレクションを編集するためのサブスクリプション。
else if Meteor.userId() return Meteor.subscribe 'profile4edit', Meteor.userId()
ルーターへのリクエストの処理:コレクションからデータを取得し、テンプレートを選択します。
action: -> @profile = null if Meteor.loggingIn() @template = 'wait' else if @params._id @profile = Collections.Profiles.findOne _id: @params._id if @profile @template = 'profile' else @template = 'invalidProfile' else if Meteor.userId() @profile = Collections.Profiles.findOne userId: Meteor.userId() if @profile @template = 'profile' else @template = 'newProfile' else @template = 'login' @render()
レンダリングのためにデータをテンプレートに渡します。
data: -> if not @profile return result = editMode: not @params._id profile: @profile return result
サブスクリプションの公開。
Meteor.publish 'profile4edit', (userId) -> check(arguments, [Match.Any]) [ Collections.Profiles.find userId: userId ] Meteor.publish 'profile4view', (id) -> check(arguments, [Match.Any]) [ Collections.Profiles.find _id: id , fields: userId: 0 ]
コレクションの
アクセス規則 。
@Collections.Profiles.allow insert: (userId, doc) -> userId and doc and userId is doc.userId update: (userId, doc, fieldNames, modifier) -> userId and doc and userId is doc.userId
PS削除は実装されていません。 祖父は、何も捨てる必要はなく、農場ですべてが役に立つと教えました。
PSS 1.0のリリース以来、Meteor
を楽しんでいます。 いくつかのオープンプロジェクト:
ブラウザーグッズ 、
ニュースフィード 、
フォームジェネレーター 、
携帯電話用フレームワーク、携帯電話用 オンラインストア 、
男 、
Trelloクローン 、
メッセージボード 、
チェリャビンスク住民向けの
教科書 。
crater.ioの流星ニュース。