问题
I am new to mustache and have reached a problem i am clueless to why it's their. I am trying to inject my page with a template using Mustache. The problem is that my function to grab and inject the template in the DOM works outside of an object but will not work inside of one.
Please any help to shine some light on this situatino would be great.
Code that works(OUTSIDE OF OBJECT):
var portfolio = {
projects: {
"proj": [
{
id:"1",
title:"Heller Recipes",
description:"This web applications was developed to keep track of my dads recipes and make them easily accesible.He is now able to check each user and make a dinner based on what everybody likes or in some cases dont like.",
technologiesUsed:"CodeIgniter, PHP, Sequel Pro, Javascript, jQuery,HTML5, CSS3, SASS, Foundation 5.0",
projectLink:"http://www.google.com",
genre:"web-app",
images: [
{largePic:"img/projects/heller-recipes/thumb.jpg",desktopImg:"img/projects/heller-recipes/desktop.png",desktopMobile:"img/projects/heller-recipes/mobile.png"}
]
},
{
id:"2",
title:"3D Animation",
description:"Created using 4D Cinema Max, a 3d anitmation program that allows you to create realistic renderings and animations.",
technologiesUsed:"CodeIgniter, PHP, Sequel Pro, Javascript, jQuery,HTML5, CSS3, SASS, Foundation 5.0",
projectLink:"http://www.google.com",
genre:"3d",
images: [
{largePic:"img/projects/4dmax.jpg",desktopImg:"img/projects/heller-recipes/desktop.png",desktopMobile:"img/projects/heller-recipes/mobile.png"}
]
},
]
}
};
$('body').on('click', '.logo', function(){
var template = $('#projects_tmp').html();
var html = Mustache.to_html(template, { "proj" : portfolio.projects.proj });
$('.portfolio-wrapper').html(html);
});
Code that will not work(INSIDE OF OBJECT):
var portfolio = {
projects: {
"proj": [
{
id:"1",
title:"Heller Recipes",
description:"This web applications was developed to keep track of my dads recipes and make them easily accesible.He is now able to check each user and make a dinner based on what everybody likes or in some cases dont like.",
technologiesUsed:"CodeIgniter, PHP, Sequel Pro, Javascript, jQuery,HTML5, CSS3, SASS, Foundation 5.0",
projectLink:"http://www.google.com",
genre:"web-app",
images: [
{largePic:"img/projects/heller-recipes/thumb.jpg",desktopImg:"img/projects/heller-recipes/desktop.png",desktopMobile:"img/projects/heller-recipes/mobile.png"}
]
},
{
id:"2",
title:"3D Animation",
description:"Created using 4D Cinema Max, a 3d anitmation program that allows you to create realistic renderings and animations.",
technologiesUsed:"CodeIgniter, PHP, Sequel Pro, Javascript, jQuery,HTML5, CSS3, SASS, Foundation 5.0",
projectLink:"http://www.google.com",
genre:"3d",
images: [
{largePic:"img/projects/4dmax.jpg",desktopImg:"img/projects/heller-recipes/desktop.png",desktopMobile:"img/projects/heller-recipes/mobile.png"}
]
},
]
},
init: function(){
var template = $('#projects_tmp').html();
var html = Mustache.to_html(template, { "proj" : portfolio.projects.proj });
$('.portfolio-wrapper').html(html);
}
}
portfolio.init();
来源:https://stackoverflow.com/questions/28754384/why-does-this-function-not-work-inside-of-an-object-but-basically-the-same-funct