我正在遵循我发现的Inline editing in magento内联编辑教程,但似乎无法使它正常工作。谁能告诉我我的代码出了什么问题?
因此我将此添加到了 config.xml
<adminhtml>
<layout>
<updates>
<Walmartapi>
<file>Mjsi_Walmartapi.xml</file>
</Walmartapi>
</updates>
</layout>
</adminhtml>
然后我将布局文件添加到app / design / adminhtml / default / default / layout / Mjsi_Walmartapi.xml
<?xml version="1.0"?>
<layout>
<adminhtml_Walmartapi_index>
<reference name="js">
<block type="core/template" template="Mjsi/Walmartapi/inline-edit.phtml" />
</reference>
</adminhtml_Walmartapi_index>
</layout>
然后我创建了模板文件 inline-edit.phtml
<script type="text/javascript">
function updateTitle(button, fieldId)
{
new Ajax.Request('<?php echo Mage::helper('adminhtml')->getUrl('*/*/update') ?>', {
method: 'post',
parameters: { id: fieldId, title: $(button).previous('input').getValue() }
});
}
</script>
并在我的控制器中添加了我的update()方法
public function updateAction()
{
$fieldId = (int) $this->getRequest()->getParam('item_id');
$title = $this->getRequest()->getParam('amount');
$this->_dd($title);
if ($fieldId) {
$model = Mage::getModel('Walmartapi/item')->load($fieldId);
$model->setTitle($title);
$model->save();
}
}