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

Re : Is it a good practise to have one base model and call different finaAll for all?

$
0
0
I think your terminology is  incorrect.  For example, it is impossible  to "inherit" from instances.

No where are you "dynamically" creating instances for the model.  I'm not sure what "dynamically" means to you, but "creating instances OF the model" means you have code like:

  1. new BaseModel()
Also, using the word "Base" in "BaseModel" would strongly indicate to another developer that you are going to inherit from BaseModel.  That code would look like:

  1. InheritedModel = BaseModel.extend({ ... }, {....})

Also, your syntax is incorrect.  Control's are passed an object.  Objects have propertiesNames and values.  For instance:

  1. Feat =can.Control.extend({ 
  2. var that = this; 
  3.        can.view('images/js/mn/temps/header.ejs', Basemodel.findAll({with overriding parameters}).then(function(d) { 
  4.         return { userdata.userdata : d};
  5.           })).done(function(frag) 
  6.            { 
  7.              that.element.html(frag); 
  8.           
  9.            })
  10.       that.display();
  11.     }});

Should almost certainly look like:

  1. Feat =can.Control.extend({ 
  2.   init: function(){
  3.        var that = this; 
  4.        can.view('images/js/mn/temps/header.ejs', Basemodel.findAll({with overriding parameters}).then(function(d) { 
  5.         return { userdata.userdata : d};
  6.           })).done(function(frag) 
  7.            { 
  8.              that.element.html(frag); 
  9.           
  10.            })
  11.       that.display();
  12.      },
  13.      display: function(){ ...}
  14.     });

Notice how I put everything in an init function.  

Make sure you use an IDE with JavaScript syntax highlighting.


Also, passing the URL is to findAll so it is used like:

  1. $.ajax({
  2.       url: params.url ,
  3.       dataType: 'json'})
  4.   }

Is almost certainly something you should not be doing.  The URLs are almost always hard-coded in a model layer. The reason is that you want something like a Person, Task, Location, that will have their own way of creating, reading, updating, and deleting data AND a host of other domain specific methods.  You might want a .complete() method on your Task model, but that would make no sense on a Location model.


So please rewrite your question with valid code and correct terminology for things like:

  • creating instances  (ex: new Constructor(...) )
  • extending or inheriting constructors (ex: Constructor.extend(...) )











Viewing all articles
Browse latest Browse all 3491

Trending Articles