mustache

面经

一曲冷凌霜 提交于 2019-12-09 07:10:23
Backbone router怎么实现页面跳转, router里面定义routes对象,在对象里面定义动作键值对,当url匹配到key时,执行相应的动作,显示相应的页面。 解释一下 Backbone 的 MVC 实现方式? Model主要负责主页面数据的获取。 View主要负责监听model事件以及与用户之间的交互。 Backbone中没有controller的概念,C的功能总是负责响应请求并调用相应的动作来让模型产生变化同时渲染视图。Backbone中主要是通过View和Router来实现的。View中通过监听DOM事件/model的change事件,实现与model的交互与视图的更新。Router实现页面间的跳转。 Backbone的优缺点。 优点: 1.分层的结构很清晰 2.backbone将页面的数据、逻辑、视图解耦,开发过程中可以将数据交互、业务逻辑、用户界面等分配给多人开发。 缺点: 1.Model层简单,对于一对多的数据结构有点应付不过来。 2.view很容易产生内存泄漏的问题。 3.对于简单页面,使用这种MVC还是有些繁琐。 什么是“前端路由”?什么时候适合使用“前端路由”? “前端路由”有哪些优点和缺点? 路由指的是根据不同的url显示不同的页面和内容;所谓的前端路由是把路由的这一功能交给前端来实现。适合用在单页面应用中,大部分页面结构不发生变化

Node.js + Express - How to get Mustache partials working?

六月ゝ 毕业季﹏ 提交于 2019-12-09 03:34:30
问题 I'm trying to get Mustache working properly with Express, and as one can guess, I'm having troubles. The following line initializes Mustache nice and clean. Variables render as expected. app.register('html', require(__dirname+'/public/js/libs/mustache.js')); However, the problems start to rise when partials are thrown in the mix. With Mustache, this here partial should invoke header view/partial. {{> header}} But alas, nothing happens. :/ Even when I offer the partial directly, Mustache fails

Mustache.js: how can i add external template

天大地大妈咪最大 提交于 2019-12-08 13:29:02
问题 Hi i am new to this Mustache.js I have a template and js code as below var template = $('#pageTpl').html(); var html = Mustache.to_html(template, data); $('#sampleArea').html(html); and this is template code: <script id="pageTpl" type="text/template"> <div data-role='page' id='videodiv_{{device_id}}'> <div data-role=header> <h1> Device Page </h1> </div> <div data-role=content> <img id='vid_{{device_id}}' src='http://localhost//mjpg/{{device_id}}' width='320'> </div> </div> </script> this code

Render complex JSON with mustache.js

自闭症网瘾萝莉.ら 提交于 2019-12-08 12:46:21
问题 I am a newbie on CouchDB. I was familiar with JSON from quiet sometime. My problem now is a I have a pretty complex JSON data. I also read some of the documentation of mustache.js and felt it was very apt to render JSON. It's fine for rendering simple JSON, but how do I do if there exists nested objects. Below is my sample JSON: { "name": "John", "email": "john@abc.com", "files": { "img1.jpg": {"content_type": "image/jpeg", "revpos": 3, "length": 33423, "stub": true}, "img2.jpg": {"content

How can accomplish For-Each loop from the underscore template to mustache

我的梦境 提交于 2019-12-08 12:33:21
问题 I have an underscore template and I have to use Mustache to render it. Below is my underscore template: <div id="sub-account"> <p>something</p> <table> <tr><td>Name</td> </tr> <tbody> <% _.each(accountList, function(account) { %> <tr> <td><%= account.get('name') %></td> </tr> <% }) %> </tbody> </table> </div> Im using a mustache as my main view to render a list. How can I loop through the code to render as a mustache template? Backbone Collection: var SubAccountCollection = Backbone

Mustache section in Couchdb issues

≡放荡痞女 提交于 2019-12-08 11:24:08
问题 I am a couchdb newbie running CouchDB 1.0.1. I have a very basic issue. I cannot get Mustache Sections to render in a list. Here is my list with the data hard coded from an example. function(head, req) { start({ "headers": { "Content-Type": "text/html" } }); var mustache = require("lib/mustache"); var view = {name: "Joe's shopping card",items: ["bananas", "apples"]}; var template = "{{name}}: <ul> {{#items}}<li>{{.}}</li>{{/items}} </ul>"; return mustache.to_html(template,view); Outputs: Joe

$.mustache() is defined, but Mustache isn't defined when mustache() is invoked

亡梦爱人 提交于 2019-12-08 06:41:14
问题 I am trying to use Mustache along with requireJS and jQuery, and it seems that it is being loaded into the browser since Chrome's console outputs correctly: >$.mustache <function (template, view, partials) { return Mustache.render(template, view, partials); } But when I try to use the mustache function it gives the error ReferenceError: Mustache is not defined and points to line 588 in the mustache.js file itself: $.mustache = function (template, view, partials) { return Mustache.render

javascript / jquery - creating an object in a particular format from a loop

此生再无相见时 提交于 2019-12-08 06:40:17
问题 I'm trying to get some data into this format, for use with a templating system called mustache: { "repo": [ { "name": "resque" }, { "name": "hub" }, { "name": "rip" }, ] } and what I currently have is this: for (childIndex in scenes[sceneID].children) { childSceneID = scenes[sceneID].children[childIndex]; childScene = scenes[childSceneID]; } So I somehow need to make each childScene the "name" in the "repo" object. Does anyone know how to do this? This is the mustache documentation: http:/

Executing function on a click event in a mustache template

孤街醉人 提交于 2019-12-08 02:14:28
问题 I have a page that is driven by a mustache template (along with javascript and jquery), and I can't figure out how to insert a function into this template. Essentially what I want is to add a link or button to the page that executes a function, " onTaskSelected(taskId) ", when the user clicks on it. I've been searching for a way to accomplish this for several days now, and extensive mustache documentation/support/examples are woefully hard to find. Does anyone know how this could be

Rendering Mustache Block with external templates

眉间皱痕 提交于 2019-12-08 00:08:59
问题 I'm using Mustache 2.7.0 and trying to play with Blocks pragma for the first time. Basically, I call basic.mustache {{< layout }} {{$ title}}{{page.meta.name}}{{/ title}} {{/ layout }} calling the block layout.mustache <!DOCTYPE html> <html> <head></head> <body> <h1>{{$ title}}test{{/ title}}</h1> </body> </html> I see the value of page.meta.name appear on the page, but not the tags written in layout.mustache . Anyone have an idea why? PHP $mustache = new Mustache_Engine(array( 'pragmas' =>