can.Model is similar to a can.Map, but it includes built-in CRUD functionality.
Questions tagged [canjs-model]
44 questions
1
vote
2 answers
Why should I put JSON server responses under a `data` field for can.Model?
On CanJS.com, it says not to return an array from a JSON service by itself. Instead, it should look like this:
{
"data": [
{"id":1, "description":"Do the dishes."},
{"id":2, "description":"Mow the lawn."},
{"id":3,…

nick lang
- 65
- 4
1
vote
2 answers
can.Model destroy with multiple parameters
I'm working with an API over which I have no control. I would like to do something like this:
var Page = can.Model.extend({
destroy: 'DELETE /api/{account_id}/{page_id}'
})
This doesn't work - canjs simply doesn't use the destroy URL. I tried…

nick lang
- 65
- 4
1
vote
2 answers
canjs findOne deferred
I learned that instead of using model.findAll and write code in call back function of findAll we can achieve same by using new model.List({}).
E.g., jsfiddle --> http://jsfiddle.net/CRZXH/48/ .. in this jsfiddle example List implementation works but…

Abhi
- 38
- 5
1
vote
1 answer
CanJS how to refresh a model
I have a model which represents a list of jobs which are run on the server
I want to poll the server for updates on a timer to show changes to the state of the jobs.
How do I do this?
My Control looks like this
var control = Control({
…

Anthony Johnston
- 9,405
- 4
- 46
- 57
1
vote
0 answers
Error callback being called when getting 200
I'm using Canjs on my app and when i call my function, the error callback is being called, but I'm getting a 200 response.
var factory = new DTO(Factory);
factory.save(
function (data) {
…

Glund
- 507
- 1
- 5
- 20
1
vote
2 answers
CanJS add custom MODEL method
I want to add another function to get result from a CanJs Model
i Have something like this:
VideomakerModel = can.Model({
id:'ID',
findAll: 'GET /videomakers/',
findNear: function( params ){
…

Magico
- 2,814
- 1
- 16
- 17
1
vote
1 answer
Getting Straight Json from Can.Model
I use a c# 4.0 service to send json objects from a mongodb database to a website running canJS. I then show the json in a textarea on my page. The problem is that the json rendered in the text area has a weird duplication:
{
"_data": {
"field1":…

ford prefect
- 7,096
- 11
- 56
- 83
1
vote
1 answer
JavaScriptMVC: How to use model findAll to encapsulate these URLs?
I have following URLs:
/tasks/ // Return a list of JSON
/task/next-week/ // Return a list of JSON
I have Task model in JSMVC:
$.Model('Task', {
findAll: 'GET /tasks/',
findOne: 'GET /task/{id}'
});
How can I support…

user469652
- 48,855
- 59
- 128
- 165
1
vote
1 answer
canJS: load model with associations, but only save the "base" model
Here is a demo, how to load a model with associations (in a single request) in canJS.
I found it in the github repo of canJS, here, and actually I had to rewrite it a little bit to work (it was outdated), but it works now.
My problem is, that if I…

Tamás Pap
- 17,777
- 15
- 70
- 102
0
votes
1 answer
How to disable model.store in can.js
Shifted to REST architecture, so don't need to store those anymore.
Is there a way how to disable the model storing at all?

nik
- 303
- 3
- 15
0
votes
1 answer
How to create *static* property in can.Model
I need somehow to store metadata in the can.Model
I use findAll method and receive such JSON:
{
"metadata": {
"color": "red"
},
"data": [
{ "id": 1, "description": "Do the dishes." },
{ "id": 2, "description":…

Pavel Bezdverniy
- 21
- 1
0
votes
1 answer
Can.Model: creating model instances from plain objects
I have a can.Model with defined findOne, findAll methods. Sometimes however it is required to create model instances from plain objects, e.g. these objects are bootstrapped in html as globals during initial page load.
The problem is that these…

pheasant
- 94
- 6
0
votes
1 answer
In canjs, what is the most idiomatic way of conditionally displaying sections of a mustache template based on the existence of any model instances?
I am iterating through each model instance in a mustache style template and want a clean way to show a message if there are no available instances (ex. if someone deletes/destroys them all)
{{#notifications}}
…

manglass
- 11
- 1
0
votes
1 answer
Canjs created event
I am trying to detect created event in component. Nothing happens.
can.Component.extend({
// todos-list component
// lists todos
tag: "todos-list",
template: can.view("javascript_view/todos-list"),
scope: {
Todo: Todo,
todos:…

php--
- 2,647
- 4
- 16
- 18
0
votes
1 answer
How do I update my view when my Model is sorted?
I have a CanJS Model.List which I'm rendering using an EJS template like follows:
<% this.each(function(item, index) { %>
<% if(index < 5 ){ %>
el.data("item", item) %> >
<%= todo.attr('name') %> (<%=…

Greg B
- 14,597
- 18
- 87
- 141