Meteor (how to publish search without autopublish)


#1

Hi, anyone please help me. I have created code search for my project. I have problem to publish the result without autopublish. This my code in html and javascript.

Carian

Maklumat

    {{#each profil}}
  1. {{jenama}}
  2. {{/each}}
//js Template.search.events({ "submit #searchform": function (e) { e.preventDefault(); Session.set("kategori", e.target.text.value); } });

Template.search.helpers({
profil: function() {
return Profil.find({
kategori: Session.get(‘kategori’),
});
}
});


#2

We can’t read your code. Please wrap your code and html snippets in triple backticks like this:

```
your code/html here
```

#4

This my code html
`

Carian

Maklumat

    {{#each profil}}
  1. {{jenama}}
  2. {{/each}}
````

//js
Template.search.events({
“submit #searchform”: function (e) {
e.preventDefault();
Session.set(“kategori”, e.target.text.value);
}
});
Template.search.helpers({
profil: function() {
return Profil.find({
kategori: Session.get(‘kategori’),
});
}
});


#5

Do you have a publication or subscription set up?


#6

No. That it I dont know how to code.


#7

Creating a publication based on a search is a bit more complicated, I’d say start with a normal publication with searchable subscription data:

server.js:

Meteor.publish('profil', function () {
  console.log('Profil Count:', Profil.find().count());
  return Profil.find();
});

client.js:

Template.search.onCreated(function () {
  var self = this;
  self.autorun(function () {
    var profilSub = self.subscribe('profil');
    if (profilSub.ready()) {
      console.log('subscribed');
    }
  });
});

Once you get that working, post back here and we can check out adding a search to the pub/sub?


#8

This code not working to my project.


#9

How about iron router? how declare searching in iron router?


#10

Well, you need your publications and subscriptions working first. Then you can add searching to your publication. Do you have any errors when using the code I posted?


#11

No any error and no any output.


#12

Can you try the edited version of the code above – check your server log as well.