嗨,您可以通過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();
}
}
});
}
和控制器白水會是這樣
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));
}
}
希望這對你有所幫助的感謝。
嗨很好做... – lordkelvin 2012-07-25 03:58:45