我在 Canvas 标签内有一个游戏。当我单击游戏实体时,我想打开一个模式并在 View 中能够访问单击对象的属性。
这是当我单击游戏实体时调用的函数:
function pause(player) {
$('myModal').modal();
}
这是呈现模式的 View :
#myModal.modal.fade(tabindex='-1', role='dialog', aria labelledby='myModalLabel', aria-hidden='true')
.modal-dialog
.modal-content
.modal-header
button.close(type='button', data-dismiss='modal', aria-label='Close')
span(aria-hidden='true') ×
h4#myModalLabel.modal-title
.modal-body
h5 Object Properties
ul.list-group
-// List all properties of the player object here
form
.form-group
label.control-label(for='script-text') Text:
input#script-text.form-control(type='text')
.modal-footer
button.btn.btn-primary.pull-left(type='button') Submit
button.btn.btn-default(type='button', data-dismiss='modal') Cancel
如何从 View 中访问 player
对象?我确信这个问题有一个简单的答案,但我似乎无法弄清楚。
最佳答案
打开模式后,您可以简单地写入 .modal-body
容器:
function pause(player) {
$('#myModal').modal().find('.modal-body').html(JSON.stringify(player));
}
当然,您可能想要更好地格式化对象属性,而不是 JSON.stringify。
关于javascript - 如何在模态视图中访问对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28385903/