javascriptcanjscanjs-model

CanJS findOne by name


I am using CanJS for a web application. I want to know how to implement search. I have implemented findAll but i want to implement findOne based on the name and not id.

var Library = can.Model({
    findAll:    "GET /libraries",
    findOne:    "GET/libraries/{id}",
    create:     'POST /libraries',
    update:     'PUT /libraries/{id}',
    destroy:    'DELETE /libraries/{id}'
}, {});

I want to implement findOne based on the name and not on ID. Can some one help me. I came accross Underscore.js. What are the other alternatives of finding based on the name.

{ "id" : 1, "name" : "CanJS", "web" : "http://canjs.us", "logo": "img/can.png" },

This is how the items in library look like.


Solution

  • You can use it without rewrite findOne function:

    MyModel.findOne({id:15,name:'canjs'})
    

    the request will be mayendpoint?id=15&name=canjs

    the Id is mandatory for RESTFUL resource if you want to keep it.