English 中文(简体)
浏览器的 Java版节目模板或类似格式
原标题:Templates or similar for JavaScript programs in the browser

我已经做了许多服务器边的超文本方案规划,并使用一些不同的模板语言制作(X)超文本。 对我来说,这一部分非常清楚。

但是,我不禁要问的是,人们如何在客户方贾瓦的圣经节目中使用这种东西? 我指的是,显然能够为 Java写模版语言,在浏览器内工作,但人们通常如何工作? 或者人们是否直接操纵了OMM? 或者,大多数人使用一些冰箱帮助图书馆?

举例来说,我要说的是, Java语版的用词是,从遥远的服务器上排出一份接触卡的清单,作为JSON的物体。 然后,我想在浏览器边使用某些预先确定的超文本标记显示这一接触卡,我填写在所需领域。 通常如何这样做?

最佳回答

通常有多种方式:

  • Storing the html in a file fetched from the server when you do your ajax call and just inserting it into the DOM
  • Getting the dynamic bits of content you want and then assembling all the HTML back on the client side and inserting it into the DOM (this is probably the most common and the one I d recommend the least)
    • Using a javascript templating language (I m fairly partial to jquery s tempest plugin)

还有其他一些解决办法,例如,隐藏在文字区或html文字标签上拟写的内容,但我不是其中的狂热,因为它们往往产生不正确/无效的标志。

问题回答

你描述的任务可以通过一个排行式系统或手工操作DOM来完成,正如在服务器方面所做的那样,可以通过一个排行式系统或一系列扼杀性分类来实现。 在个人方面,如果我不得不问这个问题,我一般会采用一种排时制度。 (事实上,如果你认为可用多数语文的印刷版格式是一个模板系统,我几乎从未使用模板操纵插图。)

我知道 Java版模版几种语言:

关闭模板令人感兴趣,因为还有一台服务器-侧使器可供使用,因此,你可以在服务器-侧代码和 Java本之间共享模板。 陪审员与TAL相当,因此也可以与陪审团一起这样做。

我接手了这里提出的解决办法,并不完全满意。 我学到的是:

  • Most people just piece together strings and assign them to elem.innerHTML. This is too ugly for me.
  • Some people build DOM with Builder objects, so in fact they are writing HTML with JavaScript for the dynamic content. This is what I d use if the content was 100% dynamic, but in this case I d rather have templates that are actually html that I can customize.
  • Some people use actual templating languages on the client-side JavaScript. That is, there is all sorts of if-constructs and while-constructs and string replacements and all that. This would be, kind-of, what I was looking for when writing the question. Just that, it seems wholly inefficient to parse a text markup client-side when you ve got the whole DOM engine at your feet.

但是,我发现,我真心想要的是,用方案方式从OMS的幻灯片中编成一个超文本,并在中间填写所需数据。 我为此找到了两种解决办法:

其中,我为我的需求而选择了万国邮联。

谢谢大家。

你是正确的。 Java本有模版图书馆。 如果能够做到简单,那么光是作为扼杀和添加到OM,届时浏览器将显示这种HTML。

这是John Resig的微型模板库: http://ejohn.org/blog/javascript-micro-templating/

我建议见习。 简单、有力、自成一体。 -





相关问题
CSS working only in Firefox

I am trying to create a search text-field like on the Apple website. The HTML looks like this: <div class="frm-search"> <div> <input class="btn" type="image" src="http://www....

image changed but appears the same in browser

I m writing a php script to crop an image. The script overwrites the old image with the new one, but when I reload the page (which is supposed to pickup the new image) I still see the old one. ...

Firefox background image horizontal centering oddity

I am building some basic HTML code for a CMS. One of the page-related options in the CMS is "background image" and "stretch page width / height to background image width / height." so that with large ...

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签