+的NodeJS前pressJS:服务器端与客户端HTML渲染 [英] NodeJS + expressJS: server-side vs. client-side html rendering

查看:161
本文介绍了+的NodeJS前pressJS:服务器端与客户端HTML渲染的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新来的NodeJS又有点困惑的服务器和客户端的HTML页面之间的区别。我的目标是建立一个电子商务网上商店的做法。我想尝试的堆栈+的NodeJS防爆preSS +的MongoDB + AngularJS。其基本结构我现在是如下图所示。

I am new to nodejs and a little confused about the distinction between the server and client side html pages. My goal is to build an e-commerce web store for practice. The stack that I want to try is NodeJS + Express + MongoDB + AngularJS. The basic structure I have right now is as below.

shoppingMall
..bin
..data
..node_modules
..public
....images
....javascripts
....stylesheets
..routes
....index.js
....users.js
..views
....index.jade
....layout.jade
..app.js
..package.json

这是我的逻辑。在的意见的文件是从服务器渲染HTML页面。在 JavaScript文件公开/ Java脚本/ 呈现在客户端。我必须包括 AngularJS layout.jade ,以及相关的索引页的任何客户端code应该去到公共/ JavaScript的/ index.js ,我必须包括 index.jade 此文件。然后,在HTML页面从服务器使用玉模板引擎渲染,任何进一步的用户交互是从客户完成。有关 index.jade 任何服务器端逻辑必须转到路由/ index.js 和code这个文件中的生活将不会被显示到客户端。

Here is my logic. The files inside views are html pages that are rendered from server. Javascript files inside public/javascripts/ are rendered on client. I have to include AngularJS inside layout.jade, and any client code related to the index page should go to public/javascripts/index.js and I must include this file from index.jade. Then, the html page is rendered from server using a jade template engine, and any further user interaction is done from client. Any server-side logic related to index.jade must go to routes/index.js and the code that lives inside this file will not be shown to client.

Q1。是我的逻辑是否正确?

Q2。假设我想保持它作为一个MVC结构,这部分对应于M,V,C在这种情况下?

推荐答案

Q1。我的逻辑是否正确?

Q1. Is my logic correct?

我的经验告诉你的逻辑是不正确。由于没有任何需要一个服务器端模板引擎(在你的情况,玉)当我们使用Angularjs。角本身能够渲染动态数据。

My experience says your logic is incorrect. Because there isn't any need for a server side templating engine (in your case, jade) when we are using Angularjs. Angular itself is capable for rendering dynamic data.

你可以做的是在这里使用节点和前preSS建设API终点为您的购物车的所有功能,然后写角所有视图(包括前端和后端)。

What you could do here is use node and express for building API end points for all the functionalities of your shopping cart and then write all the views (both frontend and backend) in Angular.

Q2。假设我想保持它作为一个MVC结构,这部分对应于M,V,C在这种情况下?

Q2. Assuming I am trying to keep it up as an MVC structure, which parts correspond to M, V, C in this case?

在角视图与应用指令和过滤器的HTML页面。以便重新presents的应用程序的UI侧。控制器是视图的大脑。

In angular View is the html page with directives and filters applied. So that represents the UI side of the application. Controllers are the brain for the views.

意见得到控制器的数据显示。和控制器经常使用的服务或工厂的API获取数据。控制器使用一个对象调用$范围将数据传递到视图。在世界的角度可以考虑这款$范围对象视图模型。这既胶合视图和控制器。

Views get data from controllers to display. And controllers often fetch data from APIs using services or factories. Controller use an object called $scope to pass data into view. In angular world you can consider this $scope object as the view model. it glues both the view and controller.

因此​​,在你的榜样,

So in your example,

/public
     /javascripts
         /item
          ..item.html // view
          ..item.js   // controller (might include the services for item api calls or write a seperate js file for them)

这篇关于+的NodeJS前pressJS:服务器端与客户端HTML渲染的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆