CanJs Model Service Method Implementations

丶灬走出姿态 提交于 2019-12-11 20:30:14

问题


I am having trouble understanding how to correctly implement the can.Model service methods. I currently have this

var Foo = can.Model({
findAll: "GET /service/Editor.svc/foo",
findOne: "GET /service/Editor.svc/foo/{id}",
create: 'POST /service/Editor.svc/foo"',
update: 'PUT /service/Editor.svc/foo"{id}',
destroy: 'DELETE /service/Editor.svc/foo"{id}'
},{});

I have looked at http://canjs.com/guides/Models.html and http://canjs.com/guides/Tutorial.html and CanJS Model findAll returns list of duplicate items

I guess what I don't understand is how the model works. Is the only thing I need for these methods the above declaration? when I try to run

var test = new Foo() then foo.findAll({}, function(success){//dosomething}, function(xhr){//do something else}) I get TypeError: Object #<Constructor> has no method 'findAll'

What part of this framework am I missing?

For the record this interacts with a c# wcf service and which pulls json objects from a mongodb


回答1:


The findAll etc. methods you are defining are constructor methods not prototype methods. That means that you have to call it on the Foo object and not the foo instance (I usually name my Model and instances of it differently as not to confuse them - e.g. var bar = new Foo()).

Foo.findAll({}, function(data) {

});

// Or a little nicer:
Foo.findAll({}).then(function(data) {

});


来源:https://stackoverflow.com/questions/19591609/canjs-model-service-method-implementations

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!