燕鹏 4 years ago
parent
commit
0dee1c0683
  1. 5
      client/main.js
  2. 1
      client/templates/main_item.js
  3. 5
      client/templates/userPage.html
  4. 5
      client/templates/user_page.html
  5. 9
      client/templates/user_page.js
  6. 9
      lib/router.js
  7. 8
      server/publication.js

5
client/main.js

@ -1,9 +1,12 @@
import { Template } from 'meteor/templating';
import { ReactiveVar } from 'meteor/reactive-var';
import "/lib/MyRes"
import './mainLayout.html';
import './templates/main_item.js'
import './templates/main_item'
import '/lib/router'
import './templates/user_page'
Template.hello.onCreated(function helloOnCreated() {
this.counter = new ReactiveVar(0);

1
client/templates/main_item.js

@ -1,5 +1,4 @@
import "./main_item.html"
import "/lib/MyRes"
Template.mainItem.helpers({
main_datas: function (){

5
client/templates/userPage.html

@ -1,5 +0,0 @@
<template name="userPage">
<div>
用户名:{{username}}
</div>
</template>

5
client/templates/user_page.html

@ -0,0 +1,5 @@
<template name="userPage">
<div>
用户名:{{user.username}}
</div>
</template>

9
client/templates/user_page.js

@ -0,0 +1,9 @@
Template.userPage.onRendered(function (){
this.subscribe("userById",Router.current().params._id)
})
Template.userPage.helpers({
user: function (){
return User.findOne(Router.current().params._id)
}
})

9
lib/router.js

@ -1,5 +1,5 @@
import "/client/templates/loading.html"
import "/client/templates/userPage.html"
import "/client/templates/user_page.html"
import "/client/templates/not_found.html"
Router.configure({
@ -11,17 +11,14 @@ Router.configure({
}
})
Meteor.subscribe('user_res')
// Meteor.subscribe('user_res')
Router.route("/")
Router.route("/nelson", {name: 'mainItem'})
Router.route("/user/:_id", {
name: 'userPage',
data(){
return User.findOne(this.params._id)
}
name: 'userPage'
})
Router.onBeforeAction('dataNotFound',{only: 'userPage'})

8
server/publication.js

@ -2,6 +2,10 @@ Meteor.publish("url_res",function () {
return UrlRes.find()
})
Meteor.publish("user_res",function () {
return User.find()
// Meteor.publish("user_res",function () {
// return User.find()
// })
Meteor.publish("userById",function (id) {
return User.find({_id:id})
})
Loading…
Cancel
Save