使用javascript将数据传递给模态

时间:2021-08-31 11:20:16

I am creating a website in MVC5 using bootstrap with the boostrap tables library http://wenzhixin.net.cn/p/bootstrap-table/docs/index.html using:

我正在MVC5中创建一个网站,使用bootstrap和boostrap表库http://wenzhixin.net.cn/p/bootstrap-table/docs/index.html使用:

$('#subscriber-table').on("click-row.bs.table", function (e, row, $element) {
                        console.log(row.SubscriberID);
                        $('#subscriberDialog').modal();
                    });

I receive the click on one of the table's records. This works great ony now I want to pass the json object called row to my created modal, so I can set the name input field. Like this:

我收到了表格记录中的一个点击。这很好用,现在我想把名为row的json对象传递给我创建的模态,所以我可以设置名称输入字段。像这样:

$('#subscriberDialog').on('show.bs.modal', function (event) {

     $('#namefield').val('toSetName');
});

I have been trying to figure this out but I cant seem to get it to work.

我一直试图解决这个问题,但我似乎无法让它发挥作用。

2 个解决方案

#1


2  

What you can do you can set any custom attribute in modal to get the value.

您可以做什么,您可以在模态中设置任何自定义属性以获取值。

like this :

像这样 :

$('#subscriber-table').on("click-row.bs.table", function (e, row, $element) {
  console.log(row.SubscriberID);
  $('#subscriberDialog').attr('data-custom-value', 'toSetName');
  $('#subscriberDialog').modal();
});


$('#subscriberDialog').on('show.bs.modal', function (event) {
     var val = $(this).attr('data-custom-value');
     $('#namefield').val(val);
});

#2


0  

Pass Through array also like OnClick(['a','b','c']);

Pass Through数组也像OnClick(['a','b','c']);

and Retrieve Like function checkData(value) { alert(value[0] + " " + value[2] .....); }

和Retrieve Like函数checkData(value){alert(value [0] +“”+ value [2] .....); }

#1


2  

What you can do you can set any custom attribute in modal to get the value.

您可以做什么,您可以在模态中设置任何自定义属性以获取值。

like this :

像这样 :

$('#subscriber-table').on("click-row.bs.table", function (e, row, $element) {
  console.log(row.SubscriberID);
  $('#subscriberDialog').attr('data-custom-value', 'toSetName');
  $('#subscriberDialog').modal();
});


$('#subscriberDialog').on('show.bs.modal', function (event) {
     var val = $(this).attr('data-custom-value');
     $('#namefield').val(val);
});

#2


0  

Pass Through array also like OnClick(['a','b','c']);

Pass Through数组也像OnClick(['a','b','c']);

and Retrieve Like function checkData(value) { alert(value[0] + " " + value[2] .....); }

和Retrieve Like函数checkData(value){alert(value [0] +“”+ value [2] .....); }