Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/81.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/haskell/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery 将onclick添加到json生成的表中_Jquery_Json - Fatal编程技术网

Jquery 将onclick添加到json生成的表中

Jquery 将onclick添加到json生成的表中,jquery,json,Jquery,Json,我有一个从数据库解析的JSON数组 $.getJSON(… , 使用$迭代数据。然后将每个按名称放入表1 function(geojson) { $.each(geojson.features, function(i, feature) { var id = feature.properties.id; var name = feature.properties.name; var otherDetails = feature.prope

我有一个从数据库解析的JSON数组

$.getJSON(… ,
使用
$迭代数据。然后将每个
按名称放入表1

function(geojson) {
    $.each(geojson.features, function(i, feature) {
        var id = feature.properties.id;
        var name = feature.properties.name;
        var otherDetails = feature.properties.otherDetails;

        // Populate table1 with clickable links
        $("#table1 table").append('<tr><td><a href="#" onclick="['+id+']; return false;">'+name+'</a></td></tr>')
            //populate table2 with name
            .click(function(){
                $("#table2 table").append('<tr><td><a">'+name+' '+otherDetails+'</a></td></tr>')
        })
    });
});
函数(geojson){
$.each(geojson.features,function(i,feature){
var id=feature.properties.id;
var name=feature.properties.name;
var otherDetails=feature.properties.otherDetails;
//用可点击的链接填充表1
$(“#表1表”)。附加(“”)
//用名称填充表2
。单击(函数(){

$(“#table2 table”)。追加(“在table1的行中添加一个单击处理程序。单击时,拉出名称以放入table2的新行中

$('#table1 table').on('click', 'tr', function()
{
    var name = $(this).find('a').text();
    $('#table2 table').append('<tr><td><a">' + name + '</a></td></tr>');
});
$('table1 table')。在('click','tr',function()上
{
var name=$(this.find('a').text();

$(“#table2 table”).append(”。这将允许您也使用otherinfo数据。

将在
table
级别重复应用
单击事件处理程序。请尝试将其应用于行,如下所示:

 // Populate table1 with clickable links
 var newRow = $('<tr><td><a href="#" onclick="['+id+']; return false;">'+name+'</a></td></tr>');
 $("#table1 table").append(newRow);
 $(newRow).click(function(){
     $("#table2 table").append('<tr><td><a">'+name+' '+otherDetails+'</a></td></tr>')
 });
//使用可单击的链接填充表1
var newRow=$('');
$(“#表1表”)。追加(新行);
$(新行)。单击(函数(){
$(“#表2表”)。追加('