doume5227 2019-07-12 17:14
浏览 238
已采纳

检查页面中的每个div并根据div中的数据更改值

i have buttons created via display suite(the buttons contain 'join' text i need to run the function check to see the value should be join or leave. you can find my js code and my check function code. my problem is i think im calling the function the wrong way.

function init() {
$('div').each(function(){
  $ajax('checkteam')
   .then(function(){
     if (res.data === true){
        var button = $(this).find('.button.pulse');
        $(button).text === 'Leave';
        $(button).data('leave', true);
     }
     else {
          }
        }       
   )  
})
}

'checkteam' => array(
  'type' => MENU_CALLBACK,
  'page callback' => 'card_generator_check_team_ajax',
  'page arguments' => array(2),
  'access arguments' => array('access content'),
),


function card_generator_check_team_ajax($term_name) {
global $user;
$term = reset(taxonomy_get_term_by_name($term_name));
$tid = $term->tid;
$user_fields = user_load($user->uid);
$arrlength = (sizeof(($user_fields->field_teams[und])));
for($x = 0; $x < $arrlength; $x++) {
$mytid = ($user_fields->field_teams[und])[$x]['tid'];
if ($tid == $mytid){
return true;
}
return false;
 }
}

i need to get the data from checkteam function and if its true then the value should be leave.

  • 写回答

3条回答 默认 最新

  • duandazhen7306 2019-07-16 16:38
    关注

    problem solved! the php function was wrong.

    function card_generator_check_team_ajax($term_name)
    {
      global $user;
      $term = reset(taxonomy_get_term_by_name($term_name));
      $tid = $term->tid;
      $user_fields = user_load($user->uid);
    
      $arrlength = (sizeof(($user_fields->field_teams[und])));
      for ($x = 0; $x < $arrlength; $x++) {
        $mytid = ($user_fields->field_teams[und])[$x]['tid'];
        if ($tid == $mytid) {
          $arr = 'true';
          continue;
        }
      }
      drupal_json_output($arr);
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 在误装Windows server2019 后如何利用Windows.old恢复?
  • ¥20 代码实现状态连接包过滤防火墙的设计与实现
  • ¥15 vscode的红色箭头爆红和has no default export报错
  • ¥15 关于#sql#的问题:#情况描述 在用vs对项目进行调试时,出现找不到网络路径,然后查看SQL配置工具,发现SQL服务显示远程调用过程失败(相关搜索:防火墙)
  • ¥15 eNSP中基于默认路由及浮动路由的公司与分部互联和校园网综合项目
  • ¥15 主要进行描述泥浆在管路不同区段泥浆的密度不相同,泥浆的密度有高有低,此时管路的摩阻分布需要怎么计算,(标签-matlab)
  • ¥40 通过编制程序计算圆管内层流充分发展对流换热,参数如图5-4,以及公式5-16所示,要求用表5-6对程序计算准确性进行验证
  • ¥20 该学习哪个编程语言? AI会取代程序员吗?
  • ¥15 ensp如何拼通IP地址
  • ¥15 saber软件导入Ibis模型报错