我已经创建了我的自定义模块。我需要将获取的数据库值$ flag = 1传递给drupal 7中的js文件。在js文件中我抓住了未定义的变量aniv'在js文件中
module file
$flag=1; //assume fetched from database
drupal_add_js(array('one_time_popup' => array('aniv' => $flag)), array('type' => 'setting'));
drupal_add_js(drupal_get_path('module', 'one_time_popup') . '/service.js','file');
$settings=variable_get('one_time_popup_effects',(ONE_TIME_POPUP_DEFAULT));
drupal_add_js(array('onetimepopupmenu'=>$settings),'settings');
service.js
console.log(Drupal.settings.one_time_popup.aniv);
答案 0 :(得分:0)
我认为一个可能的问题是行
drupal_add_js(array('onetimepopupmenu'=>$settings),'settings');
应该是setting
而不是settings
drupal_add_js(array('onetimepopupmenu'=>$settings),'setting');