我正在启动一个应用程序(我是新手)需要应用程序的单例模型...基本上,我将模板数组传递给我的实用程序js,并将模板分配给适当的视图……
我使用:
app.js、singleton.js(返回对象)、用于实现索引页面模板的index.js、用于将模板分配给适当视图的实用程序...
但是在index.js中,当我控制this.template的时候...我得到的结果是"function (n){return e.call(this,n,w)}“-我知道我的方法是错误的..有没有哪一次能给我正确的方法或者突出我做错了什么..?
提前谢谢..
下面是我所有的js文件:
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 (只返回对象)
define(function () {
var EDMS = EDMS || {};
return EDMS;
})
utilities.js (我在这里分配模板)
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;
})
最后是我的index.js,我应该在这里获取由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 i am getting as "function (n){return e.call(this,n,w)} "
}
});
})
发布于 2013-05-10 11:46:55
这对我很有效:
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;
});
谢谢大家。
https://stackoverflow.com/questions/16464245
复制相似问题