1

I'm going to implement some kind of a Pagniator class in Coffeescript. The Paginator class should hold the information about currentPage, maxPages, columnNames, ...

So my first approach is this:

class Paginator
  currentPage = -1
  rowCount = -1
  pageSize= -1
  columnNames = null
  constructor: (@config) ->

  setup: ->
    @config.ajax(
        cache: false
        type: "GET"
        contentType: "application/json"
        dataType: "json"
        success: (data) =>
          this.configurationReceived(data)

    )

  configurationReceived: (data) =>
     this.storeConfig(data)
     this.setupGUI()
     this.loadPage(1)
     $('.pagination ul li').click( ->
         Paginator.loadPage($(this).text())
         return false
      )

  storeConfig: (jsonData) =>
    rowCount = jsonData['rowAmount']
    pageSize = jsonData['pageSize']
    columns = jsonData['columns']
    return

The @config is a jsRoutes.controllers.xxx from Play 2.0 Framework jsroutes object. On Page load I do

paginator = new Paginator jsRoutes.controllers.PlayerController.paginatorConfiguration()
paginator.setup() 

But I get a "this.storeConfig is not a function" all the time. Can someone help me on that? Do I misuse the class syntax here? My aim is to have the state of the Paginator encapsulated in a Paginator object (instance). On startup I want to do some initialization stuff that is done via a AJAX call to a "route" which is a HTTP endpoint.

Thanks

1 Answer 1

1

There seems to be a problem with the indentation here:

$('.pagination ul li').click( ->
    Paginator.loadPage($(this).text())
    return false
 )   # <---

should be

$('.pagination ul li').click( ->
    Paginator.loadPage($(this).text())
    return false
)

Because of this, the following code containing the definition of the method "storeConfig" is not part of the class, therefore "this.storeConfig" is not a function.

You can easily see this if you copy-past your code into the "Try-coffescript" form at coffeescript.org and examine the JavaScript output.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, that was the issue

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.