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

Is there any built-in ability to link observe lists together like backbone relational?

$
0
0
Hi,
 
I'm new to canjs and am evaluating for use in one of my companies new products.
 
Is there any support within the observe and observ lists to link to other models?
 
meaning if I have a model something like:
 
{      "custs" : [      {"id" : 1, "name" : "cindy", "acctIds" : ["A", "B"]},
                        {"id" : 2, "name", "patty", "acctIds" : ["B", "C"]} ],
      "accts" :      [      {"id" : "A", "type" : "checking", "balance" : 1000},
                                {"id" : "B", "type" : "savings", "balance" : 100000},
                                {"id" : "C", "type" : "now", "balance" : 50} ] }
 
is there then some way to access the acct data through the acctIds in each cust like:
      theModel.attr("custs.1.acctIds").linkto(1, "accts", "id").attr("balance");      // first parm is index to observe list, second is path to new place in model (or completely different model), third parm is attribute to lookup based on the value taken from the observe list.
or is there some way to filter the accts list by a key held in the customer part of the model like:
      theModel.select("accts", "id", "custs.1.acctIds.1").attr("balance");
 
for comparison, the relational extension to backbone provides a mechanism to backbone to do this that requires declaring some metadata which describes the linkage making it look like the acct attributes are part of the linked cust.  Kinda like:
      custModel.defineLink("custs.acctIds" --> "accts.id");
      custModel.get("custs.1.balance");
of course, this is a abridgment of the code since backbone relational doesn't provide for any nesting of the models at all with its relationships - and one could argue that setting it up as metadata is a bit overkill for simple linkage.
 
And I like the architecture of canJs much better than backbone - it seems to offer many more features and is more pluggable.
 
and I don't see where it would be too hard to build a function on my own to accomplish what I need -- but was hoping for some mechanism or pattern that has already been implemented within canJs.
 
Thanks for any input.
Rand.
 

Viewing all articles
Browse latest Browse all 3491

Trending Articles