Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/magento/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 自动展开产品类别树_Javascript_Magento_Extjs - Fatal编程技术网

Javascript 自动展开产品类别树

Javascript 自动展开产品类别树,javascript,magento,extjs,Javascript,Magento,Extjs,我陷入了这个困境,基本上我需要的是一种方法来自动展开类别树节点,其中包含一个子类别节点 代码中的入口点是js/extjs/exttree checkbox.js和'catalog/category/tree.phtml' 可以使用expand()js方法在中展开节点,展开所有节点并不困难,但这会大大降低页面速度 更新: 我已经测试了以下解决方案: 更改js/extjs/ext-tree checkbox.jsrender方法添加以下内容: var tree = n.getOwnerTree();

我陷入了这个困境,基本上我需要的是一种方法来自动展开类别树节点,其中包含一个子类别节点

代码中的入口点是
js/extjs/exttree checkbox.js
'catalog/category/tree.phtml'

可以使用
expand()
js方法在中展开节点,展开所有节点并不困难,但这会大大降低页面速度

更新:

我已经测试了以下解决方案:

  • 更改
    js/extjs/ext-tree checkbox.js
    render方法添加以下内容:

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

  • 此解决方案可以工作,但它会破坏(不再显示)权限角色的树

    此解决方案解决了所有问题

     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.js的
    render
    方法中添加上述代码,因为:

     - 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;
    }
    
    现在将在重写类中使用上述代码


    谢谢你

    我做了一点bug修复和重构,并将@Obscles answer打包成一个小扩展。在GitHub上试一试:

    到目前为止,您尝试了什么?介绍似乎有点不合适您测试过这个吗?在
    render
    方法中将其添加到何处?此外,您似乎在结尾缺少一个分号。我在CE1.7.0.2中测试过这个,但它似乎不起作用。当时,我成功地使用了它。。无论如何,这可能是解决方案的一个很好的切入点,如果您发现任何问题,您可以改进答案或添加新的答案