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
So my model.js would contain only one base model: 

  BaseModel = can.Model.extend({
  findAll : function(params){
    return $.ajax({
      url: params.url ,
      dataType: 'json'})
  }
},{})

Here I am taking the parameters from the dom elements using the jquery. 

Now I was thinking to make instances of the model using the same BaseModel from the control.js file.

eg. 

Feat =can.Control.extend({ 
var that = this; 
       can.view('images/js/mn/temps/header.ejs', Basemodel.findAll({with overriding parameters}).then(function(d) { 
        return { userdata.userdata : d};
          })).done(function(frag) 
           { 
             that.element.html(frag); 
          
           })
      that.display();
    }});


Off = can.Control.extend({ 
  var that = this; 
       can.view('images/js/mn/temps/header.ejs', Basemodel.findAll({with overriding parameters}).then(function(d) { 
        return { userdata.userdata : d};
          })).done(function(frag) 
           { 
             that.element.html(frag); 
          
           })
      that.display();
    }});

$(document).ready(function() {
new Feat();
new off();
}

So here I am dynamically creating instances for the model. So will the instances created will be stored seperately ?? . So is it good way of designing the code. Also I wanna reuse the controls and models for other pages with different set of parameters later.  And will it help for caching of the data.?? 

And yes I am planning for inheriting, but from the instances I create from the Base model. 

Viewing all articles
Browse latest Browse all 3491

Trending Articles