dhia
May 3, 2016, 2:13pm
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}}
{{jenama}}
{{/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’),
});
}
});
We can’t read your code. Please wrap your code and html snippets in triple backticks like this:
```
your code/html here
```
dhia
May 3, 2016, 4:12pm
4
This my code html
`
Carian
Maklumat
{{#each profil}}
{{jenama}}
{{/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’),
});
}
});
Do you have a publication or subscription set up?
dhia
May 3, 2016, 6:17pm
6
No. That it I dont know how to code.
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?
dhia
May 3, 2016, 6:37pm
8
This code not working to my project.
dhia
May 3, 2016, 6:57pm
9
How about iron router? how declare searching in iron router?
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?
dhia
May 3, 2016, 7:01pm
11
No any error and no any output.
Can you try the edited version of the code above – check your server log as well.