1

我能够让 typeahead.js 插件在我的开发机器上运行,但是一旦我将代码推送到 heroku,它就停止了工作。以下是相关代码:

if (Meteor.isClient) {
  window.onload = function() {
    $("input.entry").typeahead({
     name: "movies",
     remote: {
      url: "http://api.rottentomatoes.com/api/public/v1.0/movies.json?apikey=####################&page_limit=5&q=%QUERY",
      dataType: 'jsonp',
      template: ["<p><strong>{{title}}</strong></p>"],
      engine: Handlebars,
      filter: function(parsedResponse) {
        var dataset = [];
        movies = parsedResponse.movies;
        for(i = 0; i < movies.length; i++) {
          dataset.push({
              value: movies[i].title,
              details: movies[i].critics_consensus,
              image: movies[i].posters.profile
          });
        }
        return dataset;
      }
    }
  });

  $('input.entry').bind('typeahead:selected', function(obj, datum) {
    Movies.insert({
      name: datum.value,
      consensus: datum.details,
      image: datum.image,
      voters: [],
      creator: Meteor.user(),
      time: Date.now()
    });
  });
}

如果我在页面加载后将 的内容粘贴window.onload到 javascript 控制台中,它可以正常工作。

有谁知道为什么这不能正常工作?

谢谢

4

2 回答 2

0

I was able to get it working by putting the typeahead.js code in this block Template.entryfield.rendered = function () { ... }

于 2013-09-11T16:44:44.520 回答
0

你的应用打开了http://api.rottentomatoes.com吗?否则你会遇到 CORS 问题。

于 2013-09-11T03:50:13.653 回答