How to add strikethrough in the js tree according condition?

前端 未结 1 1472
北荒
北荒 2021-01-27 18:11

I have created a jsTree to show the folder pathname. My problem is how do I add a strikethrough according to the condition active or inactive in the JSTree ? Hope someone can gu

相关标签:
1条回答
  • 2021-01-27 18:39

    With PHP you could have your conditional to set the value of a NULL variable to text-decoration that changes to line-through. This would be done with CSS. Simply have a conditional that checks if the value of $active is set to 0, if it is, then set the value of the null variable to display line-through. If the value of active is anything other than 0, then $strikeThrough will stay NULL and output nothing, therefor no change to text style that is wrapped in span tag.

    $strikeThrough = null;
    if($active = 0){
    $strikeThrough = 'text-decoration: line-through;'
        $output = "<span style='".$strikeThrough."'>" . $rs_wtpname . "</span>";
    }
    // no change needed for default Active
    

    IN JS, you could use the #folder_jstree nodelist to run through your list and update there. Likely within your colorNodes function you could have a conditional there to check the value of status, then append css to your value if set to 0 (inactive).

    If you are unable to get the status from PHP into JS, you could dump the value in the php code using the aforementioned method into an arbitrary data attribute or even alt attribute added to the #folder_jstree element span tag. Then retrieve that using JS and perform your conditional in JS.

    EDIT: (April 25th, 2020)

    Okay I think I see what you are doing with the JSON and your $folders_array now and how it is saving the data to be parsed in the JSON file.

    Try the following code in your php and see if it works.

    
    $folderData = mysqli_query($mysql_con,"SELECT * FROM filing_code_management");
        $arr_sql5 = db_conn_select($folderData);
        foreach ($arr_sql5 as $rs_sql5) {
        $active = $rs_sql5['status']; //--> Here you are setting active state
    }
    $folders_arr = array();
       while($row = mysqli_fetch_assoc($folderData)){
          $parentid = $row['parentid'];
          if($parentid == '0') $parentid = "#";
    
          $selected = false;$opened = false;
          if($row['id'] == 2){
             $selected = true;$opened = true;
          }
    
          //--> this would be the default state of active = 1 set in $output
          $output = $row['name'] . ' ' . "<span id='category'>". $row['category']."</span>";
          //--> Now we see if active is set to 0
          if($active === 0){
              //--> if active is set to 0 change the value of $output to reflect 'text-decoration'
              $output = "<span style='text-decoration: line-through;'>" . $row['name'] . ' ' . "<span id='category'>". $row['category']."</span></span>";
          }
          $folders_arr[] = array(
             "id" => $row['id'],
             "parent" => $parentid,
             "text" => $output, //--> save the proper $output in our array
             "category" => $row['category'],
             "state" => array("selected" => $selected,"opened"=>$opened) 
          );
       }
    
    0 讨论(0)
提交回复
热议问题