[英]How to load the json data to html via .js
here i am writing the code for loading the data from json file to .js and from .js to HTML file, but i am successfully able to load the json values to .js but not able to load the same value to html. 在这里,我正在编写用于将数据从json文件加载到.js以及从.js加载到HTML文件的代码,但是我能够成功将json值加载到.js,但无法将相同的值加载到html。 here is the code please can you help me in it.
这是代码,请您帮我一下。
HTML HTML
<ul>
<li ng-repeat="friend in friends">
<input type="button" id="button" name="{{friend.name}}" value="{{friend.name}}" onClick="checkBtn(event)"/>
{{ friend.name }}
</li>
</ul>
.js .js文件
var app = angular.module( "Demo", [] );
// I control the root of the application.
app.controller("AppController",function( $scope ) {
$.getJSON("Sample.json", function(json) {
alert(json.ColumnName+" "+json.ColumnName.length);
$scope.friends =[{name: json.ColumnName}];
});
}
);
in this it displaying the values in alert 在此它显示警报中的值
sample.json content sample.json内容
{
"ColumnName": ["Customer Id", "City", "Region", "Order Quantity", "Order Revenue", "Margin", "Date"],
"Type":["dim", "dim", "dim", "meas", "meas", "meas", "dim"]
}
actually what is happening here is, i need to load the name means the data present in ColumnName to button that too dynamically. 实际上,这里发生的是,我需要加载名称,这意味着ColumnName中存在的数据过于动态地按了按钮。 but it not loading.
但未加载。 even i am not getting any out put in HTML so please can any one guide me where i am going wrong.
即使我没有用HTML编写任何内容,也请任何人指导我哪里出错了。
I've tried something with jquery... 我已经尝试过使用jQuery ...
The HTML: HTML:
<button id="clik">Click</button>
<table id="output" border="1" width="100%"></table>
The Scipt: 密码:
$("#clik").click(function() {
$("#output").empty();
$.getJSON("copy of data.json", function(json) {
var $thead = $("<tr><th>Month</th><th>Revenue</th><th>Overhead</th></tr>");
$thead.appendTo("#output");
var $tRow = $("<tr></tr>");
$.each(json, function(index, arrayObj) {
var $tData = $("<td></td>");
for (var i in arrayObj.data) {
$tData.append(arrayObj.data[i]);
$tData.append("<br>");
}
$tRow.append($tData);
});
$("#output").append($tRow);
});
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.