0

嗨,我对 kendoUi 网格解决方案印象深刻,有没有人用 kendoui 做过 Zend 来列出数据库中的所有数据?

public function indexAction()
{
    // action body
    $generalSettingsMapper = new Application_Model_Mapper_GeneralSettingsMapper();
    $data = $generalSettingsMapper->fetchAll();
    $this->view->settings = json_encode($data);
}

从这里怎么走..?

4

1 回答 1

0

嗨,为了完成您对 kendoui 的疑问,我有一个简单的示例来为您演示,基本上继承自您所做的事情。基本上使用 json 我会做类似的事情

<script type="text/javascript">
$(document).ready(function() {

    var generalSettings = <?= $this->settings?>;

    $("#general_grid").kendoGrid({
        dataSource: {
            data: generalSettings ,
            schema: {
                model: {
                    id : "key",
                    fields: {
                        key: { type: "string" , editable: false },
                        value: { type: "string", editable: false }
                    }
                }
            }
        },
        scrollable:false,
        columns: [{ field: "key", title: "Key" , width : 150},
                { field: "value", title: "Value" ,width: 350}],
        editable: true
    });

});

function saveGeneralSettings()
{
    $("#success_message").hide();
    var griddataSource = $("#general_grid").data("kendoGrid").dataSource.data();
    var generalSettings = [];

    for (var i=0; i<griddataSource.length; i++ )
    {
        var temp = {};
        temp.key = griddataSource[i].key;
        temp.value = griddataSource[i].value;
        generalSettings.push(temp);
    }

    $.ajax({
        url: "<?= $this->baseUrl('yourmodule/yourcontroller/saveall') ?>",
        data: {general_settings :  generalSettings},
        dataType: "json",
        type: "POST",
        success: function(data){
            if (data.success == 1)
            {
                $("#success_message").show();
                $("#user_grid").data("kendoGrid").dataSource.read();
                $("#user_grid").data("kendoGrid").refresh();
            }
        }
    });
}

saveall 的控制器是这样的

public function saveallAction()
{
    $generalSettings = $this->_getParam("general_settings");  // Get the General Settings
    $generalSettingsMapper = new Application_Model_Mapper_GeneralSettingsMapper();

    $isUpdated = $generalSettingsMapper->saveAll($generalSettings);
    if ($isUpdated)
    {
        $this->_helper->json(array('success' => 1));
    }
    else
    {
        $this->_helper->json(array('success' => 0));
    }
}

希望这对您有所帮助,谢谢。

于 2012-07-25T03:58:10.677 回答