我使用 Meteor,这是有史以来最好的。我现在真的很喜欢 Web 开发,并且 javascript 变得非常有趣。
我目前正在为我的网站实施 EasySearch 解决方案,由于某种原因它不再工作了,它以前工作过。
https://github.com/matteodem/meteor-easy-search
在那段时间里,我主要致力于实现 Collectionsfs,更改数据的字段设置。
模板代码:
<div class="container">
{{> esInput index="posts" id="search" placeholder="Search Listing..." convertnumber=true }}
</div>
{{#ifEsIsSearching index="posts" id="search" logic="OR" }}
<div>Searching...</div>
{{/ifEsIsSearching}}
{{#ifEsInputIsEmpty index="posts" id="search"}}
<div class="posts">
{{#each posts}}
{{> postItem}}
{{/each}}
</div>
{{else}}
<div class="posts">
{{#esEach index="posts" id="search"}}
{{> postItem}}
{{/esEach}}
</div>
{{/ifEsInputIsEmpty}}
{{#ifEsHasNoResults index="posts" id="search" logic="OR" }}
<div class="no-results">No results found!</div>
{{/ifEsHasNoResults}}
</template>
蒙哥达代码:
Posts = new Mongo.Collection('posts');
Posts.initEasySearch(['firstName', 'lastName', 'university'], {
'limit' : 20,
'use' : 'mongo-db'
});
Posts.allow({
update: function(userId, post) { return ownsDocument(userId, post); },
remove: function(userId, post) { return ownsDocument(userId, post); },
});
Meteor.methods({
postInsert2: function(postAttributes) {
check(Meteor.userId(), String);
check(postAttributes, {
firstName: String,
lastName: String,
address: String,
phone: String,
university: String,
loanPeriod: String,
loanRate: String,
loanAmount: String,
job: String
});
...........