I am trying get data from server with json and manupulate it to html.This will be really hard to write and really unclear to understand when I scan my code again if I write it on javascript because I will get data and use jquery append to append data to html element and I should add a lot of html inline.For example:
我正在尝试使用json从服务器获取数据并将其发送到html。如果我在javascript上编写代码,那么当我再次扫描我的代码时,这将非常难以理解并且真的不清楚,因为我将获取数据并使用jquery追加来追加数据到html元素我应该添加很多html内联。例如:
$.getJSON( "json.php", function( json ) {
$.each( json, function( key, data ) {
$('#content').append('<a href="www.example.com" ><li class="class" id="id" >+data.type+</li></a><a href="www.example.com" ><li class="class1" id="id2" >+data.type1+</li></a><a href="www.example.com" ><li class="a" id="id3" >+data.type2+</li></a><a href="www.example.com" ><li class="d" id="id4" >+data.type3+</li></a><a href="www.example.com"><li class="h" id="id5" >+data.type4+</li></a><a href="www.example.com" ><li class="fg" id="id6" >+data.typ5e+</li></a><a href="www.example.com" ><li class="gfh" id="id7" >+data.type6+</li></a><a href="www.example.com" ><li class="example213" id="id8" >+data.typ7e+</li></a>');
enter code here
Imagine It will be more more big than this and I should write a lot of inline html in javascript and It will be incredible unreadable.Solution is Angular.js ng-repeat beacause I can write noormal html which is easy to read for all developers andd easy to write but I dont want to use angular.js beacuse It is slow,It contain a lot of bytes and I only want to use two of its method (ng-repeat with databinds).How can I achive this?
想象一下它会比这更大,我应该在javascript中编写很多内联html,这将是令人难以置信的难以理解的。解决方案是Angular.js ng-repeat因为我可以编写非常规的html,这对于所有开发人员而言都很容易阅读容易写但我不想使用angular.js因为它很慢,它包含很多字节,我只想使用它的两个方法(ng-repeat with databinds)。我怎么能得到这个?
1 个解决方案
#1
0
I found pretty simple way and without any template library.Just write \ tag end of each line ,native,very simple and readable.In my case I have a lot of if else statement,a lot of adding new variables, that why I cant use angular or that kind of thing and I will simply use \ tag just break line.
我找到了非常简单的方法,没有任何模板库。只需写入每个行的标签结尾,本机,非常简单和可读。在我的情况下,我有很多if else语句,很多添加新变量,这就是为什么我不能使用角度或那种东西,我将简单地使用\标签只是断线。
#1
0
I found pretty simple way and without any template library.Just write \ tag end of each line ,native,very simple and readable.In my case I have a lot of if else statement,a lot of adding new variables, that why I cant use angular or that kind of thing and I will simply use \ tag just break line.
我找到了非常简单的方法,没有任何模板库。只需写入每个行的标签结尾,本机,非常简单和可读。在我的情况下,我有很多if else语句,很多添加新变量,这就是为什么我不能使用角度或那种东西,我将简单地使用\标签只是断线。