【问题标题】:Auto Expand Product Category Tree自动展开产品类别树
【发布时间】:2012-10-28 11:40:41
【问题描述】:

我被卡住了,基本上我需要的是一种自动扩展类别树节点的方法,其中包含选中的子类别节点。

代码中的入口点是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();
            }
        }
    

此解决方案有效,但它破坏了(不再显示)权限角色树

【问题讨论】:

  • 到目前为止你尝试了什么?

标签: javascript magento extjs


【解决方案1】:

我做了一些错误修复和重构,并将@obscures 答案打包成一个小扩展。在 GitHub 上尝试一下:Kiwigrid_AutoExpandProductCategoryTree

【讨论】:

    【解决方案2】:

    因为:

     - Google sees this as a solution
    

    我的解决方案在 Php 方面,在 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;
    }
    

    现在要在重写类中包含上述代码。

    谢谢

    【讨论】:

    • 简介似乎有点格格不入
    【解决方案3】:

    这解决了所有问题

     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();
                }
            }
    

    js/extjs/ext-tree-checkbox.jsrender方法中添加上述代码

    【讨论】:

    • 你测试过这个吗?您会在render 方法中的哪个位置添加它?此外,您似乎最后缺少一个分号。我在 CE 1.7.0.2 中对此进行了测试,但似乎没有用。
    • 当时我已经成功使用了..无论如何这可能是解决方案的一个很好的切入点,如果您发现任何问题,您可以改进答案或添加一个新的
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-03-20
    • 2018-06-26
    • 2021-09-16
    • 2018-01-23
    • 1970-01-01
    • 1970-01-01
    • 2017-11-13
    相关资源
    最近更新 更多