перенаправить на html-страницу в трюфеле «app.js»

Для pet-Dapp http://truffleframework.com/tutorials/pet-shop я создал новую html-страницу, на которой отображаются усыновленные домашние животные. Метод, которому я следовал:

app.js

 App = {
 web3Provider: null,
 contracts: {},

init: function() {
// Load pets.
$.getJSON('../pets.json', function(data) {
  var petsRow = $('#petsRow');
  var petTemplate = $('#petTemplate');

  for (i = 0; i < data.length; i ++) {
    petTemplate.find('.panel-title').text(data[i].name);
    petTemplate.find('img').attr('src', data[i].picture);
    petTemplate.find('.pet-breed').text(data[i].breed);
    petTemplate.find('.pet-age').text(data[i].age);
    petTemplate.find('.pet-location').text(data[i].location);
    petTemplate.find('.btn-adopt').attr('data-id', data[i].id);

    petsRow.append(petTemplate.html());
  }
});

 return App.bindEvents();
},


 bindEvents: function() {
    $(document).on('click', '.btn-list', App.listAdopt); //Button in index.html for rendering to list.html page
    $(document).on('click', '.btn-listlist', App.listfun); //Button in list.html page for displaying adopted pets.
    $(document).on('click', '.btn-home', App.homepage);//Button in list.html for rendering to index.html
 },


 homepage: function(){
    window.location.href ="../index.html";
   },


 listAdopt: function(){
   window.location.href = "../list.html";
    },

 listfun: function(adopters, account){

  //Code to display adopted pets in list.html
   }

 };

$(function() {
 $(window).load(function() {
 console.log('Inside window Load function');
 App.init();
 });
 });

Поэтому, как только он перенаправляется на «list.html», он дает пустую страницу и при нажатии кнопки выполняет событие и отображает принятых домашних животных.

Когда страница отображается в «list.html», app.js снова загружается из App.init(), поскольку я указал скрипт в «list.html» и «index.html». Мне нужен один и тот же файл js для каждого html . страница.

Есть ли другой способ, с помощью которого усыновленные домашние животные могут отображаться в «list.html» после загрузки страницы.

Ответы (1)

Я бы добавил что-нибудь в готовый документ jquery

 Your code

$( document ).ready(function() {
App.listfun
});
Спасибо... Где я разместил этот код? я заменил $(document).on('click', '.btn-listlist', App.listfun);. Но это не работает