Quantcast
Channel: JavaScriptMVC Forum
Viewing all articles
Browse latest Browse all 3491

Re : How do i implement findAll?

$
0
0
To expand on Justin's response a bit, what you're demonstrating here, Richard, is a valid point that CanJS is not quite that magic.   It's pretty good at handling the pipeline between a REST service and client side observable data, but it doesn't in any way make $.ajax itself work differently from how you would expect.

What you did here is write a wrapper function around $.ajax in your model class.  As you might expect, this is to a large degree what can.Model.findAll does anyway, but of course there are other steps to the findAll process, like converting response data into a can.Model.List instance.

The best practice is to use findAll() as your base function for all retrieval of data.  If your CustomerAddress findAll is already implemented, getting address suggestions is going to take one of two forms:

1) address suggestions are structured as CustomerAddress objects, in which case your findAll will provide the base functionality enhanced by CanJS to make instances, and any extra params needed to make a query for suggestions can be provided by a findAllAddressSuggestions which directly calls findAll.

2) address suggestions are structured differently from CustomerAddress objects, in which case they should have their own model class with their own findAll.  You can for ease of use, if you need to, create a findAllAddressSuggestions in CustomerAddress which calls AddressSuggestion.findAll.

Viewing all articles
Browse latest Browse all 3491

Trending Articles