Als Web-Frontend-Anfänger möchte ich heute meine Erfahrungen mit der Verwendung von drei Steuerelementen aufzeichnen, nämlich dem Tabellensteuerelement jqgrid, dem Baumsteuerelement ztree und dem Diagrammsteuerelement echarts. Sie werden im Folgenden beschrieben.
1.jqgrid
Besuchen Sie zunächst die offizielle Demo-Website http://blog.mn886.net/jqGrid/. Die obige Beschreibung ist sehr hilfreich.
Das Hinzufügen von jqgrid ist relativ einfach. Legen Sie nach dem Herunterladen die JS- und CSS-Dateien jeweils in die entsprechenden Verzeichnisse und befolgen Sie die Anweisungen, wenn Sie sie verwenden
<link rel="stylesheet" type="text/css" media="screen" style="color: #000000"> href="style/ui.gqgrid-bootstrap.css"/> <script src="js%5Cgrid.locale-en.js" type="text/javascript"></script>
<br><span style="font-size: 14px">分别从相关目录下引用就可以了。<br>下边介绍一个简单的实例并且说下其中参数的设置<br></span>
<script type="text/javascript"><span style="color: #000000"> $(document).ready(<span style="color: #0000ff">function<span style="color: #000000">(){ $("#list4"<span style="color: #000000">).jqGrid({ url:"data.json"<span style="color: #000000">, datatype:"json", <span style="color: #008000">//<span style="color: #008000">数据来源,本地数据 mtype:"POST",<span style="color: #008000">//<span style="color: #008000">提交方式 width:1000<span style="color: #000000">, height:700,<span style="color: #008000">//<span style="color: #008000">高度,表格高度。可为数值、百分比或'auto' colNames:['Customer ID', 'Company Name', 'Phone','City'<span style="color: #000000">], colModel:[ {name:'CustomerID', width:'20%',align:'center'<span style="color: #000000"> }, {name:'CompanyName', width:'15%',align:'center'<span style="color: #000000">}, {name:'Phone', width:'20%', align:"center"<span style="color: #000000">}, {name:'City', width:'35%', align:"center"<span style="color: #000000"> } ], rownumbers:<span style="color: #0000ff">true,<span style="color: #008000">//<span style="color: #008000">添加左侧行号<span style="color: #008000"> //<span style="color: #008000">altRows:true,//设置为交替行表格,默认为false sortname:'CustomerID'<span style="color: #000000">, sortorder:'asc'<span style="color: #000000">, viewrecords: <span style="color: #0000ff">true,<span style="color: #008000">//<span style="color: #008000">是否在浏览导航栏显示记录总数 rowNum:15,<span style="color: #008000">//<span style="color: #008000">每页显示记录数 rowList:[1,2,3,4,5,6,7,8,9,10,10],<span style="color: #008000">//<span style="color: #008000">用于改变显示行数的下拉列表框的元素数组。 <span style="color: #000000">jsonReader:{ id: "blackId",<span style="color: #008000">//<span style="color: #008000">设置返回参数中,表格ID的名字为blackId repeatitems : <span style="color: #0000ff">false<span style="color: #000000"> }, autoScroll:"false"<span style="color: #000000">, emptyrecords: "Nothing to display",<span style="color: #008000">//<span style="color: #008000">单元格为空时的提示 celledit:"true",<span style="color: #008000">//<span style="color: #008000">启动单元格编辑功能 pager:$('#gridPager'<span style="color: #000000">) }); <span style="color: #008000">//<span style="color: #008000">navgrid用于设置toolbar $("#list4").navGrid('#gridPager'<span style="color: #000000">, { edit:<span style="color: #0000ff">true,add:<span style="color: #0000ff">true,del:<span style="color: #0000ff">true,search:<span style="color: #0000ff">true,refresh:<span style="color: #0000ff">true<span style="color: #000000">, view:<span style="color: #0000ff">true,poition:"left",cloneToTop:<span style="color: #0000ff">false<span style="color: #000000"> } ); }); </script>
Es gibt derzeit zwei Hauptprobleme, nämlich das Seitenlayout, das heißt, dass Gewicht und Höhe die Tabelle oft nicht einschränken, und gleichzeitig ist die Verwendung von Bildlaufleisten auch seltsam. Das zweite Problem besteht darin, dass die Navigationsleiste nicht an das Layout der Tabelle angepasst werden kann. Sie läuft oft herum und zeigt nur einen Teil der Seite an.
Es wurde ein Problem behoben, bei dem zwei horizontale Bildlaufleisten angezeigt wurden
<!--此行代码用来解决有两个横向滚动条的问题 --> $("#jqGrid").closest(".ui-jqgrid-bdiv").css({ "overflow-x" : "hidden" });
Im Idealfall ist der Effekt, den ich erzielen möchte, so, mit einer Tabelle und einer Navigationsleiste unten
<span style="font-size: 14px"><br><img src="http://images2015.cnblogs.com/blog/1043666/201610/1043666-20161016163934499-830322411.png" alt=""><br>当然也先附上实现上图的代码<br></span>
<span style="color: #008080"> 1</span> <script type="text/javascript"> <span style="color: #008080"> 2</span> $(document).ready(<span style="color: #0000ff">function</span><span style="color: #000000"> () { </span><span style="color: #008080"> 3</span> $("#jqGrid"<span style="color: #000000">).jqGrid({ </span><span style="color: #008080"> 4</span> url: 'data.json'<span style="color: #000000">, </span><span style="color: #008080"> 5</span> <span style="color: #008000">//</span><span style="color: #008000"> we set the changes to be made at client side using predefined word clientArray</span> <span style="color: #008080"> 6</span> editurl: 'clientArray'<span style="color: #000000">, </span><span style="color: #008080"> 7</span> datatype: "json"<span style="color: #000000">, </span><span style="color: #008080"> 8</span> <span style="color: #000000"> colModel: [ </span><span style="color: #008080"> 9</span> <span style="color: #000000"> { </span><span style="color: #008080">10</span> label: 'Customer ID'<span style="color: #000000">, </span><span style="color: #008080">11</span> name: 'CustomerID'<span style="color: #000000">, </span><span style="color: #008080">12</span> width: 90<span style="color: #000000">, </span><span style="color: #008080">13</span> key: <span style="color: #0000ff">true</span><span style="color: #000000">, </span><span style="color: #008080">14</span> editable: <span style="color: #0000ff">true</span><span style="color: #000000">, </span><span style="color: #008080">15</span> editrules : { required: <span style="color: #0000ff">true</span><span style="color: #000000">} </span><span style="color: #008080">16</span> <span style="color: #000000"> }, </span><span style="color: #008080">17</span> <span style="color: #000000"> { </span><span style="color: #008080">18</span> label: 'Company Name'<span style="color: #000000">, </span><span style="color: #008080">19</span> name: 'CompanyName'<span style="color: #000000">, </span><span style="color: #008080">20</span> width: 160<span style="color: #000000">, </span><span style="color: #008080">21</span> editable: <span style="color: #0000ff">true</span> <span style="color: #008000">//</span><span style="color: #008000"> must set editable to true if you want to make the field editable</span> <span style="color: #008080">22</span> <span style="color: #000000"> }, </span><span style="color: #008080">23</span> <span style="color: #000000"> { </span><span style="color: #008080">24</span> label : 'Phone'<span style="color: #000000">, </span><span style="color: #008080">25</span> name: 'Phone'<span style="color: #000000">, </span><span style="color: #008080">26</span> width: 140<span style="color: #000000">, </span><span style="color: #008080">27</span> editable: <span style="color: #0000ff">true</span> <span style="color: #008080">28</span> <span style="color: #000000"> }, </span><span style="color: #008080">29</span> <span style="color: #000000"> { </span><span style="color: #008080">30</span> label: 'Postal Code'<span style="color: #000000">, </span><span style="color: #008080">31</span> name: 'PostalCode'<span style="color: #000000">, </span><span style="color: #008080">32</span> width: 100<span style="color: #000000">, </span><span style="color: #008080">33</span> editable: <span style="color: #0000ff">true</span> <span style="color: #008080">34</span> <span style="color: #000000"> }, </span><span style="color: #008080">35</span> <span style="color: #000000"> { </span><span style="color: #008080">36</span> label: 'City'<span style="color: #000000">, </span><span style="color: #008080">37</span> name: 'City'<span style="color: #000000">, </span><span style="color: #008080">38</span> width: 140<span style="color: #000000">, </span><span style="color: #008080">39</span> editable: <span style="color: #0000ff">true</span> <span style="color: #008080">40</span> <span style="color: #000000"> } </span><span style="color: #008080">41</span> <span style="color: #000000"> ], </span><span style="color: #008080">42</span> sortname: 'CustomerID'<span style="color: #000000">, </span><span style="color: #008080">43</span> sortorder : 'asc'<span style="color: #000000">, </span><span style="color: #008080">44</span> loadonce: <span style="color: #0000ff">true</span><span style="color: #000000">, </span><span style="color: #008080">45</span> viewrecords: <span style="color: #0000ff">true</span><span style="color: #000000">, </span><span style="color: #008080">46</span> height: "auto"<span style="color: #000000">, </span><span style="color: #008080">47</span> weight:"auto"<span style="color: #000000">, </span><span style="color: #008080">48</span> rowNum: 10<span style="color: #000000">, </span><span style="color: #008080">49</span> pager: "#jqGridPager"<span style="color: #000000">, </span><span style="color: #008080">50</span> <span style="color: #008080">51</span> <span style="color: #000000"> }); </span><span style="color: #008080">52</span> <!--此行代码用来解决有两个横向滚动条的问题 --> <span style="color: #008080">53</span> $("#jqGrid").closest(".ui-jqgrid-bdiv").css({ "overflow-x" : "hidden"<span style="color: #000000"> }); </span><span style="color: #008080">54</span> <span style="color: #008080">55</span> $('#jqGrid').navGrid('#jqGridPager'<span style="color: #000000">, </span><span style="color: #008080">56</span> <span style="color: #008000">//</span><span style="color: #008000"> the buttons to appear on the toolbar of the grid</span> <span style="color: #008080">57</span> { edit: <span style="color: #0000ff">true</span>, add: <span style="color: #0000ff">true</span>, del: <span style="color: #0000ff">true</span>, search: <span style="color: #0000ff">false</span>, refresh: <span style="color: #0000ff">false</span>, view: <span style="color: #0000ff">false</span><span style="color: #000000">, </span><span style="color: #008080">58</span> position: "left", cloneToTop: <span style="color: #0000ff">false</span><span style="color: #000000"> }, </span><span style="color: #008080">59</span> <span style="color: #008000">//</span><span style="color: #008000"> options for the Edit Dialog</span> <span style="color: #008080">60</span> <span style="color: #000000"> { </span><span style="color: #008080">61</span> editCaption: "The Edit Dialog"<span style="color: #000000">, </span><span style="color: #008080">62</span> recreateForm: <span style="color: #0000ff">true</span><span style="color: #000000">, </span><span style="color: #008080">63</span> checkOnUpdate : <span style="color: #0000ff">true</span><span style="color: #000000">, </span><span style="color: #008080">64</span> checkOnSubmit : <span style="color: #0000ff">true</span><span style="color: #000000">, </span><span style="color: #008080">65</span> closeAfterEdit: <span style="color: #0000ff">true</span><span style="color: #000000">, </span><span style="color: #008080">66</span> errorTextFormat: <span style="color: #0000ff">function</span><span style="color: #000000"> (data) { </span><span style="color: #008080">67</span> <span style="color: #0000ff">return</span> 'Error: ' +<span style="color: #000000"> data.responseText </span><span style="color: #008080">68</span> <span style="color: #000000"> } </span><span style="color: #008080">69</span> <span style="color: #000000"> }, </span><span style="color: #008080">70</span> <span style="color: #008000">//</span><span style="color: #008000"> options for the Add Dialog</span> <span style="color: #008080">71</span> <span style="color: #000000"> { </span><span style="color: #008080">72</span> closeAfterAdd: <span style="color: #0000ff">true</span><span style="color: #000000">, </span><span style="color: #008080">73</span> recreateForm: <span style="color: #0000ff">true</span><span style="color: #000000">, </span><span style="color: #008080">74</span> errorTextFormat: <span style="color: #0000ff">function</span><span style="color: #000000"> (data) { </span><span style="color: #008080">75</span> <span style="color: #0000ff">return</span> 'Error: ' +<span style="color: #000000"> data.responseText </span><span style="color: #008080">76</span> <span style="color: #000000"> } </span><span style="color: #008080">77</span> <span style="color: #000000"> }, </span><span style="color: #008080">78</span> <span style="color: #008000">//</span><span style="color: #008000"> options for the Delete Dailog</span> <span style="color: #008080">79</span> <span style="color: #000000"> { </span><span style="color: #008080">80</span> errorTextFormat: <span style="color: #0000ff">function</span><span style="color: #000000"> (data) { </span><span style="color: #008080">81</span> <span style="color: #0000ff">return</span> 'Error: ' +<span style="color: #000000"> data.responseText </span><span style="color: #008080">82</span> <span style="color: #000000"> } </span><span style="color: #008080">83</span> <span style="color: #000000"> }); </span><span style="color: #008080">84</span> <span style="color: #000000"> }); </span><span style="color: #008080">85</span> </script>
Ich verstehe den Inhalt von navGrid noch nicht ganz, daher werde ich nächste Woche eine neue Zusammenfassung erstellen.
Die andere Sache besteht darin, das Datenformat JSON zu verwenden und die ID mit demselben Namen wie der JSON zur Steuerung zu verwenden.
Lass uns hier zuerst aufhören, über jqgrid zu reden, und dann darüber reden, wenn wir ein neues Verständnis haben.
2. ztree
Bitte fügen Sie zuerst die offizielle Adresse bei: http://www.treejs.cn/v3/demo.php#_102.
Die Zitiermethode ist immer noch dieselbe
<span style="color: #008080">1</span> <link rel="stylesheet" href="styles/demo.css" type="text/css"> <span style="color: #008080">2</span> <link rel="stylesheet" href="styles/zTreeStyle.css" type="text/css"> <span style="color: #008080">3</span> <script type="text/javascript" src="js/jquery-1.4.4.min.js"></script> <span style="color: #008080">4</span> <script type="text/javascript" src="js/jquery.ztree.core.js"></script>
Fügen Sie zunächst den einfachsten Baum hinzu, um ein Beispiel zu geben
<span style="color: #008080"> 1</span> <SCRIPT type="text/javascript"> <span style="color: #008080"> 2</span> <!-- <span style="color: #008080"> 3</span> <span style="color: #0000ff">var</span> setting =<span style="color: #000000"> { }; </span><span style="color: #008080"> 4</span> <span style="color: #008080"> 5</span> <span style="color: #0000ff">var</span> zNodes =<span style="color: #000000">[ </span><span style="color: #008080"> 6</span> { name:"父节点1 - 展开", open:<span style="color: #0000ff">true</span><span style="color: #000000">, </span><span style="color: #008080"> 7</span> <span style="color: #000000"> children: [ </span><span style="color: #008080"> 8</span> { name:"父节点11 - 折叠"<span style="color: #000000">, </span><span style="color: #008080"> 9</span> <span style="color: #000000"> children: [ </span><span style="color: #008080">10</span> { name:"叶子节点111"<span style="color: #000000">}, </span><span style="color: #008080">11</span> { name:"叶子节点112"<span style="color: #000000">}, </span><span style="color: #008080">12</span> { name:"叶子节点113"<span style="color: #000000">}, </span><span style="color: #008080">13</span> { name:"叶子节点114"<span style="color: #000000">} </span><span style="color: #008080">14</span> <span style="color: #000000"> ]}, </span><span style="color: #008080">15</span> { name:"父节点12 - 折叠"<span style="color: #000000">, </span><span style="color: #008080">16</span> <span style="color: #000000"> children: [ </span><span style="color: #008080">17</span> { name:"叶子节点121"<span style="color: #000000">}, </span><span style="color: #008080">18</span> { name:"叶子节点122"<span style="color: #000000">}, </span><span style="color: #008080">19</span> { name:"叶子节点123"<span style="color: #000000">}, </span><span style="color: #008080">20</span> { name:"叶子节点124"<span style="color: #000000">} </span><span style="color: #008080">21</span> <span style="color: #000000"> ]}, </span><span style="color: #008080">22</span> { name:"父节点13 - 没有子节点", isParent:<span style="color: #0000ff">true</span><span style="color: #000000">} </span><span style="color: #008080">23</span> <span style="color: #000000"> ]}, </span><span style="color: #008080">24</span> { name:"父节点2 - 折叠"<span style="color: #000000">, </span><span style="color: #008080">25</span> <span style="color: #000000"> children: [ </span><span style="color: #008080">26</span> { name:"父节点21 - 展开", open:<span style="color: #0000ff">true</span><span style="color: #000000">, </span><span style="color: #008080">27</span> <span style="color: #000000"> children: [ </span><span style="color: #008080">28</span> { name:"叶子节点211"<span style="color: #000000">}, </span><span style="color: #008080">29</span> { name:"叶子节点212"<span style="color: #000000">}, </span><span style="color: #008080">30</span> { name:"叶子节点213"<span style="color: #000000">}, </span><span style="color: #008080">31</span> { name:"叶子节点214"<span style="color: #000000">} </span><span style="color: #008080">32</span> <span style="color: #000000"> ]}, </span><span style="color: #008080">33</span> { name:"父节点22 - 折叠"<span style="color: #000000">, </span><span style="color: #008080">34</span> <span style="color: #000000"> children: [ </span><span style="color: #008080">35</span> { name:"叶子节点221"<span style="color: #000000">}, </span><span style="color: #008080">36</span> { name:"叶子节点222"<span style="color: #000000">}, </span><span style="color: #008080">37</span> { name:"叶子节点223"<span style="color: #000000">}, </span><span style="color: #008080">38</span> { name:"叶子节点224"<span style="color: #000000">} </span><span style="color: #008080">39</span> <span style="color: #000000"> ]}, </span><span style="color: #008080">40</span> { name:"父节点23 - 折叠"<span style="color: #000000">, </span><span style="color: #008080">41</span> <span style="color: #000000"> children: [ </span><span style="color: #008080">42</span> { name:"叶子节点231"<span style="color: #000000">}, </span><span style="color: #008080">43</span> { name:"叶子节点232"<span style="color: #000000">}, </span><span style="color: #008080">44</span> { name:"叶子节点233"<span style="color: #000000">}, </span><span style="color: #008080">45</span> { name:"叶子节点234"<span style="color: #000000">} </span><span style="color: #008080">46</span> <span style="color: #000000"> ]} </span><span style="color: #008080">47</span> <span style="color: #000000"> ]}, </span><span style="color: #008080">48</span> { name:"父节点3 - 没有子节点", isParent:<span style="color: #0000ff">true</span><span style="color: #000000">} </span><span style="color: #008080">49</span> <span style="color: #008080">50</span> <span style="color: #000000"> ]; </span><span style="color: #008080">51</span> <span style="color: #008080">52</span> $(document).ready(<span style="color: #0000ff">function</span><span style="color: #000000">(){ </span><span style="color: #008080">53</span> $.fn.zTree.init($("#treeDemo"<span style="color: #000000">), setting, zNodes); </span><span style="color: #008080">54</span> <span style="color: #000000"> }); </span><span style="color: #008080">55</span> <span style="color: #008000">//</span><span style="color: #008000">--></span> <span style="color: #008080">56</span> </SCRIPT>
stellt die Baumstruktur dar, indem neue Knoten unter dem übergeordneten Knoten erstellt werden. Legen Sie zunächst die Einstellung bzw. die Znodes zu Beginn fest und verwenden Sie dann die Initialisierungsfunktion init, um die Einstellung und die Znodes als Initialisierungsparameter für die Initialisierung festzulegen.
Es gibt zwei Hauptprobleme, die jetzt gelöst werden müssen. Zum einen ist die Baumstruktur verschwunden und der gesamte Text erscheint in derselben Spalte ohne Einrückung. Die zweite Möglichkeit besteht darin, JSON-Daten zur Steuerung anstelle einer direkten Eingabe zu referenzieren. Poste es, wenn es gelöst ist.
Lassen Sie uns über zwei weitere Dinge sprechen. Der Speicherort zum Anpassen des Baumstils befindet sich in der Datei demo.css. Ändern Sie ihn in den Namen, den Sie verwenden möchten ;ul> Verwenden Sie einfach die Klasse, um darauf zu verweisen.
Der zweite ist der Stil des gesamten Baums. Ändern Sie einfach das a-Tag in der Ademo.
Das dritte Plug-in ist Echarts. Ehrlich gesagt macht die Verwendung dieses Plug-ins am meisten Spaß.
Fügen Sie zunächst die offizielle Website-Adresse hinzu: http://echarts.baidu.com/.
Um auf dieses Plug-in zu verweisen, brauchen Sie nur
Das ist es.
Im Anhang finden Sie zunächst die einfachste Implementierung.
<span style="color: #008080"> 1</span> <script type="text/javascript"> <span style="color: #008080"> 2</span> <span style="color: #008000">//</span><span style="color: #008000"> 基于准备好的dom,初始化echarts实例</span> <span style="color: #008080"> 3</span> <span style="color: #0000ff">var</span> myChart = echarts.init(document.getElementById('cdataTableQuery2'<span style="color: #000000">)); </span><span style="color: #008080"> 4</span> <span style="color: #008080"> 5</span> <span style="color: #008000">//</span><span style="color: #008000"> 指定图表的配置项和数据</span> <span style="color: #008080"> 6</span> <span style="color: #0000ff">var</span> option =<span style="color: #000000"> { </span><span style="color: #008080"> 7</span> <span style="color: #000000"> title: { </span><span style="color: #008080"> 8</span> text: '图表展示' <span style="color: #008080"> 9</span> <span style="color: #000000"> }, </span><span style="color: #008080">10</span> <span style="color: #000000"> tooltip: {}, </span><span style="color: #008080">11</span> <span style="color: #000000"> legend: { </span><span style="color: #008080">12</span> data:['数目'<span style="color: #000000">] </span><span style="color: #008080">13</span> <span style="color: #000000"> }, </span><span style="color: #008080">14</span> <span style="color: #000000"> xAxis: { </span><span style="color: #008080">15</span> data: ["沉降点","涵洞","水文孔","天气","地下水","不良路段"<span style="color: #000000">] </span><span style="color: #008080">16</span> <span style="color: #000000"> }, </span><span style="color: #008080">17</span> <span style="color: #000000"> yAxis: {}, </span><span style="color: #008080">18</span> <span style="color: #000000"> series: [{ </span><span style="color: #008080">19</span> name: '数目'<span style="color: #000000">, </span><span style="color: #008080">20</span> <span style="color: #000000"> itemStyle:{ </span><span style="color: #008080">21</span> <span style="color: #000000"> normal:{ </span><span style="color: #008080">22</span> color: <span style="color: #0000ff">function</span><span style="color: #000000">(params) { </span><span style="color: #008080">23</span> <span style="color: #008000">//</span><span style="color: #008000"> build a color map as your need.</span> <span style="color: #008080">24</span> <span style="color: #0000ff">var</span> colorList =<span style="color: #000000"> [ </span><span style="color: #008080">25</span> '#C1232B','#B5C334','#FCCE10','#E87C25','#27727B'<span style="color: #000000">, </span><span style="color: #008080">26</span> '#FE8463','#9BCA63','#FAD860','#F3A43B','#60C0DD'<span style="color: #000000">, </span><span style="color: #008080">27</span> '#D7504B','#C6E579','#F4E001','#F0805A','#26C0C0' <span style="color: #008080">28</span> <span style="color: #000000"> ]; </span><span style="color: #008080">29</span> <span style="color: #0000ff">return</span><span style="color: #000000"> colorList[params.dataIndex] </span><span style="color: #008080">30</span> <span style="color: #000000"> }, </span><span style="color: #008080">31</span> <span style="color: #000000"> } </span><span style="color: #008080">32</span> <span style="color: #000000"> }, </span><span style="color: #008080">33</span> type: 'bar'<span style="color: #000000">, </span><span style="color: #008080">34</span> data: [5, 35, 36, 20, 88, 99<span style="color: #000000">] </span><span style="color: #008080">35</span> <span style="color: #000000"> }] </span><span style="color: #008080">36</span> <span style="color: #000000"> }; </span><span style="color: #008080">37</span> <span style="color: #008080">38</span> <span style="color: #008000">//</span><span style="color: #008000"> 使用刚指定的配置项和数据显示图表。</span> <span style="color: #008080">39</span> <span style="color: #000000"> myChart.setOption(option); </span><span style="color: #008080">40</span> </script>
16.10.2016 17:27:09
<span style="font-size: 14px"> </span>