0
我有一个从数据库填充的实体数组,每个实体都有自己的GUID。我将它们显示在网页(HTML)上,方法是循环遍历实体数组,并将每个数组放入一个新的动态创建的包装器div
中。如何动态地将数据从PHP传递到JavaScript(在动态创建的HTML元素中)
<?php
$images = elgg_extract('entities', $vars, FALSE);
foreach ($images as $image) {
$img = elgg_view_entity_icon($image, 'small');
$image_guid = $image -> getGUID();
echo <<<HTML
<div class="file-preview-frame">
<div class="image-preview">{$img}</div>
<button type="button" class="btn-default" data-guid={$image_guid}></button>
</div>
HTML;
}
elgg_require_js('js/inline_image_view');
inline_image_view.js
require(['elgg/Ajax'], Ajax => {
var ajax = new Ajax();
$('.btn-default').click(function(event) {
var button = $(event.relatedTarget) // Button that triggered the modal
var recipient = button.data('guid') // Extract info from data-* attributes
ajax.view('albums/inline_full_image_view', {
data: {
guid: recipient // querystring
},
}).then(body => {
$('.full-image-view').html(body);
})
});
});
我怎么能去在inline_image_view.js在RequireJS每个按钮的点击与特定图像的GUID?什么是最好的,或者优先考虑的方式?
谢谢大家提前?
昨天我回答了你准备好了。 http://stackoverflow.com/questions/38247952/how-can-i-go-about-passing-data-from-one-php-file-to-another-via-javascript/38249068#38249068 :-) –
In这个问题,元素是在循环中动态创建的。每个应该保持一个唯一的GUID。 –