2012-10-28 70 views
5

我被困在這,基本上我需要的是一種自動展開包含檢查子類別節點的類別樹節點的方法。Auto Expand產品分類樹

代碼的入口點是js/extjs/ext-tree-checkbox.js'catalog/category/tree.phtml'

這是可能的擴大與expand() JS方法的一個節點,它是沒有困難的展開所有節點,但這種緩慢下跌的一頁太多。

更新:

我已經測試了以下解決方案:

  1. 變化js/extjs/ext-tree-checkbox.js渲染方法添加此:

    var tree = n.getOwnerTree(); 
        if (tree){ 
         expandNodeIds = tree.expandNodeIds.split(','); 
         for (i in expandNodeIds) 
         { 
          if (n.id == expandNodeIds[i]) 
           n.expand(); 
         } 
        } 
    

該解決方案的工作,但它打破(它不再顯示)樹許可角色

+0

你到目前爲止嘗試了什麼? – Alex

回答

1

這解決所有問題

var tree = n.getOwnerTree(); 
    if (tree){ 
     expandNodeIds = tree.expandNodeIds; 

     if (expandNodeIds) { 
      expandNodeIds = expandNodeIds.split(','); 
      for (i in expandNodeIds) 
      { 
       if (n.id == expandNodeIds[i]) 
        n.expand(); 
      } 
     } 

添加上面的代碼中的render方法js/extjs/ext-tree-checkbox.js

+0

你測試過了嗎?你在哪裏將它添加到'render'方法中?此外,你似乎在最後錯過了一個分號。我已經在CE 1.7.0.2中測試過了,它似乎沒有工作。 –

+0

在那個時候,我已經成功地使用它..無論如何這可能是一個很好的解決方案的入口點,如果你發現任何問題,你可以改進答案或添加一個新的 – WonderLand

2

因爲:

- Google sees this as a solution 

我的解決辦法是在腓側,在類Mage_Adminhtml_Block_Catalog_Product_Edit_Tab_Categories。

// start Added stuff 
protected $_ubProductCategoriesParents; 

public function getUbProductCategories() 
{ 
    if (is_null($this->_ubProductCategoriesParents)) { 
     $this->_ubProductCategoriesParents = array(); 
     $this->_ubProductCategoriesParents = array(); 
     foreach ($this->getCategoryIds() as $id) { 
      $storeId = (int) $this->getRequest()->getParam('store'); 
      $path = Mage::getResourceModel('catalog/category') 
       ->getAttributeRawValue($id, 'path', $storeId); // no model->load ever ever ever 
      if (empty($path)) { 
       $path = ""; 
      } 
      $parentsIds = explode("/", $path); 
      if (!(is_array($parentsIds) && count($parentsIds) > 0)) { 
       $parentsIds = array(); 
      } 
      $this->_ubProductCategoriesParents = array_unique(array_merge($this->_ubProductCategoriesParents, $parentsIds)); 
     } 

     //Mage::log(print_r($this->_ubProductCategoriesParents, true)); 
    } 

    return $this->_ubProductCategoriesParents; 
} 
// end Added stuff 

// magento core function from class 
protected function _getNodeJson($node, $level = 1) 
{ 
    $item = parent::_getNodeJson($node, $level); 

    if ($this->_isParentSelectedCategory($node)) { 
     $item['expanded'] = true; 
    } 

    // added new if statement 
    if (!(isset($item['expanded']) && $item['expanded'] == true) && array_search($node->getId(), $this->getUbProductCategories()) !== false) { 
     $item['expanded'] = true; 
    } 

    if (in_array($node->getId(), $this->getCategoryIds())) { 
     $item['checked'] = true; 
    } 

    if ($this->isReadonly()) { 
     $item['disabled'] = true; 
    } 

    return $item; 
} 

現在要在重寫類中擁有上述代碼。

謝謝

+0

介紹似乎有點不合適 – RacerNerd

+0

我改變它,thx – obscure