backbone.js - Requirejs - using singleton object, unable to get the returning template -
i starting app (i new requirejs) requirejs singleton model of app... passing array of templates utilities js, , assigning templates appropriate views...
i use :
app.js,singleton.js(to return object), index.js implement index page template, utilities assigning templates appropriate views...
but in index.js, while console this.template... getting result "function (n){return e.call(this,n,w)} " - understand approach wrong.. can once give me correct way me.. or highlight me wrong pelase..?
thanks in advance..
here js files:
app.js:-
requirejs.config({ baseurl: 'js', paths: { "jquery" : 'lib/jquery-1.9.1.min', "underscore": "lib/underscore-min", "backbone" : "lib/backbone-min", "singleton" : "utils/singleton", "model" : "models/model", "index" : "views/index", "utils" : "utils/utils", }, shim:{ "underscore":{ exports: '_' }, "backbone":{ exports: 'backbone', deps:['underscore'] }, "utils" : { deps:['index'], deps:['model'] } } }); require(["jquery","underscore","backbone","singleton","utils","index"],function ($,_,backbone,obj) { obj.maketemp(['index']); });
singleton.js (just returns object)
define(function () { var edms = edms || {}; return edms; })
utilities.js (where assign templates)
define(["underscore", "singleton","model","index"],function (_,obj,model) { var edms = obj || {}; edms.maketemp = function(views){ $.each(views, function(index,view){ if(view){ var temp = $.get('templates/' + view + '.html') .done(function(data){ edms[view].prototype.template = _.template(data); new edms.index; }) }else{ console.log("no template found!") } }); } return edms; })
finally index.js, should suppose template, assigned utilities.js
define(["singleton","underscore","backbone","utils"],function (obj,_,backbone) { var edms = obj || {}; edms.index = backbone.view.extend({ initialize:function(){ console.log(this.template); error getting "function (n){return e.call(this,n,w)} " } }); })
this works me:
define(['singleton',"underscore","backbone"],function (obj,_,backbone) { window.edms = obj || {}; var temps = function(views){ var tempts = []; $.each(views, function(i,view){ var data = $.get("templates/"+views+".html"); data.done(function(res){ edms[views].prototype.template = _.template(res); new edms.index; }); }) }; return temps; });
thanks all.
Comments
Post a Comment