【问题标题】:Meteor onRendered Unexpected token =Meteor onRendered 意外令牌 =
【发布时间】:2015-06-22 14:52:08
【问题描述】:

在流星模板中使用 JQuery 插件时遇到问题。我试过this插件。

 <div id="listId">
  <ul class="list">
      // A bunch of items
  </ul>
  <ul class="pagination"></ul>
</div>

<script>
  var options = {
    valueNames: [ 'name', 'category' ],
    page: 3,
    plugins: [
      ListPagination({})
    ]
  };

  var listObj = new List('listId', options);
</script>

我在 onRendered 中放了关于 javascript 的代码。

Template.MyTemplate.onRendered({
    listObj = new List('listId', {
      valueNames: [ 'name', 'category' ],
      page: 3,
      plugins: [
        ListPagination({})
      ]
    });`enter code here`
});

但我遇到了错误。

MyTemplate.js:2:13: Unexpected token =

【问题讨论】:

    标签: javascript jquery meteor meteor-helper


    【解决方案1】:

    您正在将对象 ({}) 传递给 onRendered 函数:

    Template.MyTemplate.onRendered({
        listObj = new List('listId', {
          valueNames: [ 'name', 'category' ],
          page: 3,
          plugins: [
            ListPagination({})
          ]
        });
    });
    

    你应该传递函数:

    Template.MyTemplate.onRendered(function() {
        listObj = new List('listId', {
          valueNames: [ 'name', 'category' ],
          page: 3,
          plugins: [
            ListPagination({})
          ]
        });
    });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-01-19
      • 2017-11-18
      • 1970-01-01
      • 2019-08-06
      • 2014-11-29
      • 2018-11-19
      • 2017-04-17
      • 2019-05-26
      相关资源
      最近更新 更多