Javascript 多控制器yii2中的Bootstrap模型
我有一个视图Javascript 多控制器yii2中的Bootstrap模型,javascript,modal-dialog,yii2,bootstrap-modal,yii2-advanced-app,Javascript,Modal Dialog,Yii2,Bootstrap Modal,Yii2 Advanced App,我有一个视图签入和消息,我想在签入/索引页面中将消息/创建显示为模式 以下是我迄今为止所做的工作 <div class="checkin-index"> <h1><?= Html::encode($this->title) ?></h1> <?php // echo $this->render('_search', ['model' => $searchModel]); ?> <div class="com
签入
和消息
,我想在签入/索引
页面中将消息/创建
显示为模式
以下是我迄今为止所做的工作
<div class="checkin-index">
<h1><?= Html::encode($this->title) ?></h1>
<?php // echo $this->render('_search', ['model' => $searchModel]); ?>
<div class="common-button">
<p>
<?= Html::a('Send Message', ['message/create'] ,['class' => 'btn btn-danger','id' => 'buttonMessage','data-pjax' => '0']) ?>
</p>
</div>
<?php
Modal::begin(['id' =>'modalMessage']);
Modal::end();
?>
<?php Pjax::begin(['id' => 'event-grid', 'timeout' => false]); ?>
<?= GridView::widget([
'dataProvider' => $dataProvider,
'filterModel' => $searchModel,
'showOnEmpty'=>true,
'columns' => [
[
'class' => 'yii\grid\CheckboxColumn',
],
[
'attribute' => 'event_id',
'label' => 'Event Title',
'value' => 'event.title'
],
[
'attribute' => 'fullName',
'label' => 'Name',
'value' => 'users.fullname',
],
[
'attribute' => 'user_id',
'label' => 'Email',
'value' => 'users.email',
],
'user_type',
],
]);
?>
<?php Pjax::end(); ?>
<?php
// You only need add this,
$this->registerJs('
var gridview_id = ""; // specific gridview
var columns = [2]; // index column that will grouping, start 1
var column_data = [];
column_start = [];
rowspan = [];
for (var i = 0; i < columns.length; i++) {
column = columns[i];
column_data[column] = "";
column_start[column] = null;
rowspan[column] = 1;
}
var row = 1;
$(gridview_id+" table > tbody > tr").each(function() {
var col = 1;
$(this).find("td").each(function(){
for (var i = 0; i < columns.length; i++) {
if(col==columns[i]){
if(column_data[columns[i]] == $(this).html()){
$(this).remove();
rowspan[columns[i]]++;
$(column_start[columns[i]]).attr("rowspan",rowspan[columns[i]]);
}
else{
column_data[columns[i]] = $(this).html();
rowspan[columns[i]] = 1;
column_start[columns[i]] = $(this);
}
}
}
col++;
})
row++;
});
');
$this->registerJs(
'$( document ).ajaxStart(function() {
$("body").addClass("loading");
});
$( document ).ajaxComplete(function() {
$("body").removeClass("loading");
});'
);
但是当我点击send message
按钮时,它不会打开模式,但会在firebug
中显示一些错误
Synchronous XMLHttpRequest on the main thread is deprecated because of its
detrimental effects to the end user's experience.
For more help, check http://xhr.spec.whatwg.org/.
那么我在这里做错了什么???
我是否需要指定某个地方,它来自不同的型号
和控制器
我正在呼叫???请尝试以下方法:
$(function() {
$('#buttonMessage').click(function(e) {
e.preventDefault();
$('#modal').modal('show').find('.modal-content')
.load($(this).attr('href'));
});
});
我已经更新了我尝试过你的方法的问题,现在它打开了一个空模式,并重定向到
消息/create
查看页面和什么是.attr('data-link')
??什么是数据链接???数据链接
用于从您指定的url获取数据。所以它应该是这样的,没有变化.load($(this.attr('data-link'))代码>因为我尝试了这个方法并加载($(this.attr('value'))
但是它会重定向到消息/创建
页面,我以前也尝试过,它在firebug
中显示了一些奇怪的错误,比如主线程上的同步XMLHttpRequest被弃用
删除“echo”;`并查看更新的代码。
$(function() {
$('#buttonMessage').click(function(e) {
e.preventDefault();
$('#modal').modal('show').find('.modal-content')
.load($(this).attr('href'));
});
});