【发布时间】:2016-01-12 13:06:23
【问题描述】:
我把这个例子改成了一个简单的例子。当我单击“删除此 {{item.id}}”按钮时,我想调用删除函数。标题成功获取item.id值。
<h4 class="modal-title" id="exampleModalLabel">Do you want to remove {{item.id}}</h4>
但是按钮没有获取 item.id 值并且该功能不起作用。而不是“Remove this item.id”,而只是“Remove this”,并且函数也没有获取参数。
<button type="button" id="exampleModalLabel" class="btn btn-primary" ng-click="removeItem(item.id)">Remove this {{item.id}}</button>
我拥有的是这样的:
<tr ng-repeat="item in items">
<td>{{item.id}}</td>
<td><button type="button" class="btn btn-primary" data-toggle="modal" data-target="#exampleModal" data-whatever="{{item.id}}">Remove this item?</button></td>
</tr>
<div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title" id="exampleModalLabel">Do you want to remove {{item.id}}</h4>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary" ng-click="removeItem(item)">Remove this {{item.id}}</button>
</div>
</div>
</div>
</div>
//And this javascript
$('#exampleModal').on('show.bs.modal', function (event) {
var button = $(event.relatedTarget);
var recipient = button.data('whatever');
var modal = $(this);
modal.find('.modal-title').text('New message to ' + recipient);
modal.find('.modal-body input').val(recipient);
});
我希望信息足够。如果您需要更多信息,请告诉我。
【问题讨论】:
-
不应该 removeItem(item.id) 是 removeItem({{ item.id }}) 吗?
-
不,同样的结果......它甚至没有在innerHTML上得到它......
-
Modal 是否出现在屏幕上?
-
您始终可以通过 javascript 设置值来解决问题。在 JS 中设置值: var item = '{{item.id}}';然后在您的模态函数中: modal.find('.modal-body button').attr("ng-click", "removeItem("+item+")");
-
@PaulMoldovan 我试过了,但还是不行……
标签: javascript jquery angularjs twitter-bootstrap bootstrap-modal