Advertisement
Trigub_Ilia

Реализация справочников в CRM

Sep 12th, 2018
234
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.69 KB | None | 0 0
  1. #Создаем 2 инфоблока, связываем их, по ID
  2. #Создаем 2 пользовательских свойства, тип привязка к эл. инфоблока
  3. #js код
  4. Array.prototype.in_array = function(needle) {
  5.    for(var i = 0, l = this.length; i < l; i++)  {
  6.       if(this[i] == needle) {
  7.          return true;
  8.       }
  9.    }
  10.    return false;
  11. }
  12.  
  13. $(document).ready(function(){
  14.  
  15.     $("select[name=UF_CLASSIFICATION] option").hide();
  16.  
  17.     $("select[name=UF_CLASSIFICATION]").attr("disabled","disabled");
  18.  
  19.  
  20.     /*Classification*/
  21.     $("select[name=UF_CATEGORY]").change(function(){
  22.         var categoryId = $(this).val();
  23.  
  24.         var dataAjax = {};
  25.  
  26.         dataAjax["categoryId"] = categoryId;
  27.  
  28.         $.ajax({
  29.             type:'POST',
  30.             url:'/local/ajax/support_classification.php',
  31.             success:function(data){
  32.  
  33.                 $("select[name=UF_CLASSIFICATION]").removeAttr("disabled");
  34.  
  35.                 $("select[name=UF_CLASSIFICATION] option").each(function(){
  36.                     var val = parseInt($(this).attr("value"));
  37.  
  38.                     if(!data.in_array(val)){
  39.                         $(this).hide();
  40.                     }else{
  41.                         $(this).show();
  42.                     }
  43.  
  44.                 });
  45.  
  46.             },
  47.             data:dataAjax,
  48.             dataType:'json'
  49.         });
  50.     });
  51. });
  52.  
  53. #PHP код
  54. <?
  55. require($_SERVER["DOCUMENT_ROOT"]."/bitrix/modules/main/include/prolog_before.php");
  56.  
  57. CModule::IncludeModule("iblock");
  58.  
  59. $cID = $arr["VALUE"];
  60.  
  61. $objClassification = CIBlockElement::GetList(
  62.     array("ID"=>"ASC"),
  63.     Array("IBLOCK_ID" => 38, "PROPERTY_ID" => intval($_REQUEST["categoryId"])),
  64.     false,
  65.     false,
  66.     Array("ID", "NAME", "IBLOCK_ID",)
  67. );
  68.  
  69. while($arrClassification = $objClassification->Fetch()){
  70.     $arClassification[] = $arrClassification["ID"];
  71. }
  72.  
  73. echo json_encode($arClassification);
  74. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement