diff --git a/demos/search/app.js b/demos/search/app.js index f7e434ea..343bbb6b 100644 --- a/demos/search/app.js +++ b/demos/search/app.js @@ -82,13 +82,18 @@ var SearchView = Backbone.View.extend({ \
\ ', - + render: function() { - // templateResults is just for one result ... - var tmpl = '{{#records}}' + this.templateResults + '{{/records}}'; - var results = Mustache.render(tmpl, { - records: this.model.records.toJSON() - }); + var results = ''; + if (_.isFunction(this.templateResults)) { + var results = _.map(this.model.records.toJSON(), this.templateResults).join('\n'); + } else { + // templateResults is just for one result ... + var tmpl = '{{#records}}' + this.templateResults + '{{/records}}'; + var results = Mustache.render(tmpl, { + records: this.model.records.toJSON() + }); + } var html = Mustache.render(this.template, { results: results }); @@ -116,6 +121,73 @@ var SearchView = Backbone.View.extend({ // Stuff very specific to this demo function setupMoreComplexExample(config) { + var $el = $('.search-here'); + var dataset = new recline.Model.Dataset(config); + // async as may be fetching remote + dataset.fetch().done(function() { + if (dataset.get('url').indexOf('openspending') === -1) { + // generic template function + var template = function(record) { + var template = 'This demo shows how Recline can be used to build a search app. It includes faceting as well as seearch. You can find the source javascript here – please feel free to reuse!
-The default version uses some local example data but you can also connect directly to any other backend supported by Recline, in particular SOLR or ElasticSearch.
+The default version uses some local example data but you can also connect directly to any other backend supported by Recline, in particular SOLR or ElasticSearch. For example, here's an example of this app running off the OpenSpending SOLR-style search API.