0

i have a problem where for some reason my .js file is not loaded to browser, when other files are. The problem is that the file that should be loaded is important for my "site" to work. Heres code:

var viewModel = new PeopleTableViewModel({ 
// uncaught reference error      Peopetable view model is not defined
pageSize: 25,
current: data.length,
context: document.getElementById('table')
});

var comparator = new Comparators();

function init() {
viewModel.next();
}

Heres my HTML :

    <div id="table"></div>

    <button onclick="viewModel.prev()">PREV</button>
    <button onclick="viewModel.next()">NEXT</button>


    <script type="application/javascript" src="scripts/DATA.js"></script>
    <script type="application/javascript" src="scripts/Comparators.js"></script>
    <script type="application/javascript" scr="scripts/PeopleTableViewModel.js"></script>
    <script type="application/javascript" src="scripts/ListOfPeople.js"></script>
    <script type="application/javascript" src="scripts/scripts.js"></script>
    <script type="application/javascript" src="scripts/Person.js"></script>

</body>

And PeopleTableViewModel.js:

function PeopleTableViewModel(config) {
  var self = this;
  self.people = new ListOfPeople();
  self.currentPage = 0;
  self.pageSize = config.pageSize;
  self.context = config.context;

  self.next = function() {
    //alert('kliknąłeś następny');
    self.people.clear();
    var begin = (self.currentPage) * self.pageSize;
    var end = (self.currentPage + 1) * self.pageSize;
    getData(begin, end);
    self.currentPage++;
    self.context.innerHTML = self.people.toTable();
  }
  self.prev = function() {
    //alert('kliknąłeś poprzedi');
    self.people.clear();
    if (self.currentPage - 1 >= 0) {
      self.currentPage--;
    }
    var begin = (self.currentPage) * self.pageSize;
    var end = (self.currentPage + 1) * self.pageSize;
    getData(begin, end);
    self.context.innerHTML = self.people.toTable();
  }

  self.sort = function(comparer) {
    data.sort(comparer);
    self.currentPage = 0;
    self.next();
  }

  var getData = function(begin, end) {
    if (end > data.length) {
      end = data.length;
    }
    if (begin < 0) {
      begin = 0;
    }
    for (var i = begin; i < end; i += 1) {
      self.people.addPerson(data[i]);
    }
  }
}

Thank you for taking time on my issue !

2
  • Have you tried by including the file using script tag? Commented Oct 24, 2016 at 17:50
  • Where is the code at the top executed? Make sure PeopleTableViewModel.js is being included before that. Commented Oct 24, 2016 at 17:50

1 Answer 1

1

You made a mistake in the html markup.

<script type="application/javascript" scr="scripts/PeopleTableViewModel.js"></script>

instead of

<script type="application/javascript" src="scripts/PeopleTableViewModel.js"></script>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.