批量操作不适用于Magento后端网格序列化程序

时间:2015-04-01 07:40:32

标签: php magento backend

我使用this tutorial使用网格序列化器在选项卡内创建了一个网格。然后我使用this tutorial向此网格添加了一个massaction。

出现质量操作块,但是当我选择实体时,选择massaction并单击Submit,将以下错误抛出到浏览器的控制台:

"ReferenceError: {gridId}_massactionJsObject is not defined"

有没有人尝试过向标签内的网格添加批量操作?如何解决这个错误?

2 个答案:

答案 0 :(得分:4)

不要在抽象类中删除var,只需将对象设置为窗口即可。

app / design / adminhtml / default / default / template / widget / grid.phtml中的

调用getAdditionalJavascript()

在您的网格文件中添加此功能。

protected function getAdditionalJavascript() {
    return 'window.{gridId}_massactionJsObject = {gridId}_massactionJsObject;';
}

答案 1 :(得分:2)

我今天刚刚尝试过,并在Magento CE 1.8上遇到了同样的问题。经过一番挖掘,一位同事和我发现 grid.phtml (第207-224行)中的JavaScript正在运行但没有出现在DOM中(仍然不确定原因)。使用控制台时,我们注意到//wrapping your logic in a namespace helps reduce the chances of naming collisions of functions and variables between different imported js files var localNameSpace = function() { //private array containing our strings to randomly select var obliqueStrategy = [ "Abandon normal instruments" , "Accept advice" , "Accretion" , "A line has two sides" ]; var api = { //bindButtonAction binds the generateRandomStrategy function to the click event of the againbutton bindButtonAction: function() { $('#wrapper .againbutton').click(api.generateRandomStrategy); } , generateRandomStrategy: function() { //get the position of one of the string randomly //Math.random() returns a float value < 1 so multiplying it by 100 gets us a range of (0.* - 99.*) //then we Math.floor() that to get rid of the float value and keep just the integer part //finally we modulus it with the length of the string array //if you are unfamiliar with modulus, what it does is gives you the remainder of a division. for instance 10 / 3 gives you 3 with a remainder of 1, so 10 % 3 would be just 1. //what this does for us is keeps the random offset of our within the bounds of the array length (0 to length -1) var randomOffset = Math.floor(Math.random() * 100) % obliqueStrategy.length; //finally once we have the offset, we set the html to the string at the position in the array $('#wrapper #strategyBox #strategyText').html( obliqueStrategy[randomOffset] ); } }; return api; }(); $(document).ready(function() { //here we call the bind action so the button will work, but we also explicitly call the generateRandomStrategy function so the page will preload with a random string at the start localNameSpace.bindButtonAction(); localNameSpace.generateRandomStrategy(); }); 对象是可访问的,因为它是全局的,因为它是在没有varienGrid的情况下定义的。

话虽如此,我们在函数var(第225行)中的 Abstract.php 中找到了质量动作js,并从变量定义中删除了getJavascript()。这解决了我们的问题,希望能帮到你。此外,您不应该修改核心。该文件应该复制到本地并在那里进行修改。

grid.phtml - app / design / adminhtml / default / default / template / widget / grid.phtml

Abstract.php - app / code / core / Mage / Adminhtml / Block / Widget / Grid / Massaction / Abstract.php