简体   繁体   English

单击按钮将Jade文件附加到父Jade文件中的div中

[英]Append a Jade file to a div in parent Jade file on Button click

I tried to find solution for the past 3 days but no luck. 我试图在过去三天找到解决方案,但没有运气。

My requirement is to load highcharts which has some data for analysis. 我的要求是加载包含一些数据以供分析的图表 I have to load 50 such charts with each chart holding a million points . 我必须加载50个这样的图表,每个图表拥有一百万点 To get rid of the browser collapse, I decided to load 10 charts at once and give a show more button at the bottom of the page which onclick should load another 10 charts on the same page below the existing 10. 为了避免浏览器崩溃,我决定一次加载10个图表,并在页面底部显示一个更多显示按钮, onclick应该在现有10个图表的同一页面上再加载10个图表。

Issue: 问题:

  • No idea on how to append a jade file to a div on a button click to the existing jade file . 不知道如何通过单击现有的玉器按钮将玉器文件附加到div

What i did: 我做了什么:

  • I have two jade file named jade1to10.jade and jade11to20.jade with there respective .js(angular) files for charts configurations. 我有两个名为jade1to10.jade和jade11to20.jade的jade文件,其中分别具有用于图表配置的.js(角度)文件。
  • I can load them individually on different tabs. 我可以将它们分别加载到不同的选项卡上。
  • I tried Include option in jade but that loads on the compile time and want the second page to load/append to the parent jade after the button click . 我尝试了翡翠中的“ 包含”选项,但是在编译时加载,并且希望在单击按钮后第二页加载/附加到父翡翠中

I am using angular controllers in the jade to load charts. 我在翡翠中使用角度控制器加载图表。 Please give your inputs to find a fix. 请提供您的输入以找到解决方法。 Thanks in advance. 提前致谢。

OK, I think I got it. 好吧,我想我明白了。

Actually you need to use ajax. 实际上,您需要使用ajax。 When the user clicks the button, then send a ajax request to the server and return the charts in html form to you. 当用户单击按钮时,然后将ajax请求发送到服务器,并以html格式返回图表给您。 Finally just insert them into your div. 最后,只需将它们插入您的div中即可。

To compile the file from jade form into html form, See the following example. 要将文件从jade形式编译为html形式,请参见以下示例。

var jade = require('jade')
var file = fs.... //onefile, must be a string.
var template = jade.compile(file)
var result = template(locals) //the locals is a object which contains the variables you want to pass to the template. 

....
app('/',function(req,res){
    res.send(result)
)

You can also just pass the data to the client, and transform them into which you want then insert into the div. 您也可以只将数据传递给客户端,然后将其转换为所需的内容,然后插入div中。 That can reduce the network consumption. 这样可以减少网络消耗。

Hope it will be helpful. 希望对您有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM