Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/85.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Meteor中代码的重新初始化_Javascript_Jquery_Meteor - Fatal编程技术网

Javascript Meteor中代码的重新初始化

Javascript Meteor中代码的重新初始化,javascript,jquery,meteor,Javascript,Jquery,Meteor,我今天开始为一个电子商务网站编写Meteor应用程序。这是我的basic.js文件中的一些代码 Router.route("/shop", function () { this.layout("shop"); this.render("catalog"); }); 当呈现/shop时,执行shop.js中的某些代码: Template.shop.rendered = function () { if ($("figure").hasClass("selected")) {

我今天开始为一个电子商务网站编写Meteor应用程序。这是我的
basic.js
文件中的一些代码

Router.route("/shop", function () {

  this.layout("shop");
  this.render("catalog");

});
当呈现
/shop
时,执行
shop.js
中的某些代码:

Template.shop.rendered = function () {
  if ($("figure").hasClass("selected")) {
    var
      productSelected = $("figure.selected"),
      productPrice = productSelected.data("price"),
      productTitle = productSelected.data("product"),
      productLocation = productSelected.find("a").attr("href");

    $(".product-title").html(productTitle);
    $(".product-cost").html(productPrice);
    $(".content__info__title--overview").find("a").attr("href", productLocation);
  }

  // Slideshow
  var galleryItems = $(".content").children("section");

  galleryItems.each(function () {
    var container = $(this);

    // Update slider when user clicks on the preview images
    container.on("click", ".move-down, .move-up", function (event) {
      event.preventDefault();

      if ($(this).hasClass("move-down")) {
        nextSlide(container);
      } else {
        prevSlide(container);
      }

      if ($(this).hasClass("selected")) {
        var
          productPrice = $(this).data("price"),
          productTitle = $(this).data("product");

        $(".product-title").html(productTitle);
        $(".product-cost").html(productPrice);
      }
    });
  });

  // Next Slide
  function nextSlide(container, n) {
    var visibleSlide = container.find("figure.selected");

    if (typeof n === "undefined") {
      n = visibleSlide.index() + 1;
    }

    $("figure.selected").removeClass("selected");

    $(".content__products figure").eq(n).addClass("selected").removeClass("move-down").prevAll().removeClass("move-down move-up").addClass("hide-up").end().prev().removeClass("hide-up").addClass("move-up").end().next().addClass("move-down");
  }

  // Previous Slide
  function prevSlide(container, n) {
    var visibleSlide = container.find("figure.selected");

    if (typeof n === "undefined") {
      n = visibleSlide.index() - 1;
    }

    $("figure.selected").removeClass("selected");

    $(".content__products figure").eq(n).addClass("selected").removeClass("move-up hide-up").nextAll().removeClass("hide-up move-down move-up").end().next().addClass("move-down").end().prev().removeClass("hide-up").addClass("move-up");
  }

});

现在,当应用程序加载时,这一切都很好,但是当我访问另一条路线并返回时,
shop.js
中的所有代码都不起作用。我不确定我是否做错了什么,但我希望能得到一些提示。

在评论中回答了我的问题。我只需要将
Template.shop.rendered
更改为
Template.catalog.rendered
。好悲伤

在评论中回答了我的问题。我只需要将
Template.shop.rendered
更改为
Template.catalog.rendered
。好悲伤

在评论中回答了我的问题。我只需要将
Template.shop.rendered
更改为
Template.catalog.rendered
。好悲伤

在评论中回答了我的问题。我只需要将
Template.shop.rendered
更改为
Template.catalog.rendered
。好悲伤

更改从此模板渲染的模板

Template.shop.rendered

Template.catalog.rendered

因为您希望呈现的是
目录路由
,而不是
布局模板


顺便说一句,我询问meteor版本,因为在新的1.0.4 meteor版本上,
Template.shop.rendered=function(){}
被弃用,现在我们使用
Template.tabletsList.onRendered(function(){}),请尝试运行meteor update。

更改此文件中呈现的模板

Template.shop.rendered

Template.catalog.rendered

因为您希望呈现的是
目录路由
,而不是
布局模板


顺便说一句,我询问meteor版本,因为在新的1.0.4 meteor版本上,
Template.shop.rendered=function(){}
被弃用,现在我们使用
Template.tabletsList.onRendered(function(){}),请尝试运行meteor update。

更改此文件中呈现的模板

Template.shop.rendered

Template.catalog.rendered

因为您希望呈现的是
目录路由
,而不是
布局模板


顺便说一句,我询问meteor版本,因为在新的1.0.4 meteor版本上,
Template.shop.rendered=function(){}
被弃用,现在我们使用
Template.tabletsList.onRendered(function(){}),请尝试运行meteor update。

更改此文件中呈现的模板

Template.shop.rendered

Template.catalog.rendered

因为您希望呈现的是
目录路由
,而不是
布局模板



顺便说一句,我询问meteor版本,因为在新的1.0.4 meteor版本上,
Template.shop.rendered=function(){}
被弃用,现在我们使用
Template.tabletsList.onRendered(function(){}),尝试运行meteor update。

如果将
模板.shop.rendered
更改为
模板.catalog.rendered
,会发生什么情况?另外,在Meteor上运行此功能的内容
shell Meteor--version
shop
更改为
catalog
工作正常!对谢谢@Ethaan!我正在运行Meteor 1.0.3.2和Meteorite版本0.9.3。如果将
Template.shop.rendered
更改为
Template.catalog.rendered
,会发生什么?另外,在Meteor上运行此功能的内容
shell Meteor--version
shop
更改为
catalog
工作正常!对谢谢@Ethaan!我正在运行Meteor 1.0.3.2和Meteorite版本0.9.3。如果将
Template.shop.rendered
更改为
Template.catalog.rendered
,会发生什么?另外,在Meteor上运行此功能的内容
shell Meteor--version
shop
更改为
catalog
工作正常!对谢谢@Ethaan!我正在运行Meteor 1.0.3.2和Meteorite版本0.9.3。如果将
Template.shop.rendered
更改为
Template.catalog.rendered
,会发生什么?另外,在Meteor上运行此功能的内容
shell Meteor--version
shop
更改为
catalog
工作正常!对谢谢@Ethaan!我正在运行Meteor 1.0.3.2和Meteorite版本0.9.3.opps。我刚刚发布了一个答案,哈哈,这对我来说比我想承认的要多。请记住这一点!我刚刚发布了一个答案,哈哈,这种事发生在我身上的次数比我愿意承认的要多。请记住这一点!我刚刚发布了一个答案,哈哈,这种事发生在我身上的次数比我愿意承认的要多。请记住这一点!我刚刚发布了一个答案,哈哈,这种事发生在我身上的次数比我愿意承认的要多。请记住这一点!这会再次发生。我运行了更新,我的代码仍然有效。不过,我会更新到新的语法。我运行了更新,我的代码仍然有效。不过,我会更新到新的语法。我运行了更新,我的代码仍然有效。不过,我会更新到新的语法。我运行了更新,我的代码仍然有效。不过,我会更新到新语法。