These are chat archives for canjs/canjs

20th
Jun 2016
Sunil George
@georgesunil81
Jun 20 2016 19:40
@phillipskevin . I need your help with a problem I am facing. This is where I have a define getter function in a model that does not get called when the template is getting rendered. I know you had asked me to put the model on the scope, but I am not able to figure out how. Could you help me?
I have created a gist for you -
Could you help me with it once you get a chance?
I am putting the response from the model on the scope and it works fine, but not sure how to put the instance of the model on scope. That is perhaps why it is not able to find {{_Status}} when the template is rendered. Could you take a look at it and let me know what I can do to make it work.
I am using the AMD syntax.
Sunil George
@georgesunil81
Jun 20 2016 19:46
The _Status getter is supposed to get the verbose status corresponding to the numeric status returned by the ajax call.
Kevin Phillips
@phillipskevin
Jun 20 2016 20:28
the problem is that you’re not rendering the template with instances of your model
you’re just using response.data
you should implement findAll instead of using a custom getJobsList function
Sunil George
@georgesunil81
Jun 20 2016 21:04
Thanks @phillipskevin . But there will be instances where I will need to utilize custom function instead of findAll, fineOne, etc. In such cases how do I work with getter functions?
Kevin Phillips
@phillipskevin
Jun 20 2016 21:05
why will you need to have custom functions?
Sunil George
@georgesunil81
Jun 20 2016 21:05
Hmmm @phillipskevin, I am thinking...
Kevin Phillips
@phillipskevin
Jun 20 2016 21:05
you can implement findOne, findAll, etc with functions
if you need to use custom functions for some reason, just make the Map separate
and have your functions return instances of the Map
Sunil George
@georgesunil81
Jun 20 2016 21:09
making the map separate, how would I do that?
Is there any example that I can look at? You may modify my gist.
Meanwhile, I am trying to implement findAll as a function and checking...
Kevin Phillips
@phillipskevin
Jun 20 2016 21:13
something like
var MyMap = can.Map.extend({
    define: {
        _Status: {
       }
    }
});

var jobs = can.Model.extend({                

  getJobsList: function(params, success, error) {          

    return can.ajax({
      type: 'GET',
              url: '/job/All?' + params.queryString,
    })            
    .then(function (data) {
      data.map(function (item) {
        item = new MyMap(item);
      })
      success(data);
    }, error);
  }    
}, { });
that’s really not the best way to do it though
Sunil George
@georgesunil81
Jun 20 2016 21:17
Okay, so I implemented findAll as a function (substituted findAll instead of getJobsList in my gist) and it works. I get _Status getter resolved correctly in my template.
So, that way it works.
Kevin Phillips
@phillipskevin
Jun 20 2016 21:18
great
Sunil George
@georgesunil81
Jun 20 2016 21:18
Thanks for providing a solution where I may need to have my own custom function. I was not aware of using findAll as a function before.
Kevin Phillips
@phillipskevin
Jun 20 2016 21:19
you’re welcome
Sunil George
@georgesunil81
Jun 20 2016 21:19
So, it looks like I may never need to use my own custom function. I will try further use cases to see if I need any custom function or not. If I do, I will let you know and also will keep the above code snippet in mind.
Kevin Phillips
@phillipskevin
Jun 20 2016 21:20
ok
that code is totally untested
Sunil George
@georgesunil81
Jun 20 2016 21:20
no problem @phillipskevin I understand.
Kevin Phillips
@phillipskevin
Jun 20 2016 21:20
just trying to show what I mean about separating the Map
Sunil George
@georgesunil81
Jun 20 2016 21:20
Thanks a lot for your help with letting me know about using findAll as a function. I was not aware of that. It solves my problem for now.
Kevin Phillips
@phillipskevin
Jun 20 2016 21:21
good
Sunil George
@georgesunil81
Jun 20 2016 21:21
Absolutely, thanks @phillipskevin
Kevin Phillips
@phillipskevin
Jun 20 2016 21:21
:thumbsup:
Sunil George
@georgesunil81
Jun 20 2016 21:21
:thumbsup: