我知道这要求太高了,但我找不到任何关于我所做的事情的好教程。我正在从数据库中获取数据,并在html页面上使用foreach来显示字段。就像这样。
<script type="text/javascript" src="<?php echo base_url();?>js/learnKO.js?<?php echo date('l jS \of F Y h:i:s A');?>" ></script>
<div class="table-responsive">
<table class="table table-striped table-bordered table-condensed">
<thead>
<tr>
<th class="text-center">1</th>
<th class="text-center">2</th>
<th class="text-center">3</th>
</tr>
</thead>
<tbody data-bind="foreach: alldata">
<tr>
<td class="text-center"><span data-bind="text: $data.net_amount "></span></td>
<td class="text-center"><span data-bind="text: $data.vat_amount"></span></td>
<td>
<button type="button" class="btn btn-default btn-xs" data-bind="click: $parent.editItem">Edit</button>
<button type="button" class="btn btn-default btn-xs" data-bind="click: $parent.acceptItem">Accept</button>
<button type="button" class="btn btn-default btn-xs" data-bind="click: $parent.cancelItem">Cancel</button>
</td>
</tr>
</tbody>
</table>
</div>我的js文件包含一个简单的函数,它像这样获取数据。
self.alldata = ko.observableArray();
self.viewAllInvoice = function () {
$.ajax({
type: 'POST',
url: BASEURL + 'index.php/moneyexchange/learn_Ko/' ,
contentType: 'application/json; charset=utf-8'
})
.done(function(invoices) {
self.alldata.removeAll();
$.each(invoices, function (index, invoice) {
self.alldata.push(invoice);
});
})
.fail(function(xhr, status, error) {
alert(status);
})
.always(function(data){
});
};
self.viewAllInvoice();我使用phpcode点火器来获取数据。这是我如何从控制器和模型中获得的。
public function learn_Ko(){
$this->load->model('invoice_page');
$result = $this->invoice_page->getAllInvoice();
$this->output->set_content_type('application/json');
$this->output->set_output(json_encode($result));
}这是一个模型
public function getAllInvoice(){
$query ='SELECT * FROM invoice';
$query = $this->db->query($query);
$result = $query->result();
return $result;
}我想要做的就是编辑表和要存储在数据库中的编辑后的数据。请按步骤指导我,因为我尝试了很多不同的教程,但都做不到。我在这里提供了一切,所以我确信我没有错过任何东西。这是桌子上的图片

发布于 2016-02-02 19:55:56
对于PHP应用程序,我会在服务器中使用OData服务(我确信在JavaScript中肯定有一些实现,例如参见:How to create an Odata Service using PHP?)和出色的breeze.js库。
Breeze.js以一种非常简单和强大的方式处理所有CRUD内容以及与OData服务的通信。并且可以很好地使用knockout:您只需在breeze之前加载konockout库,这样breeze就可以检测到它。如果这样做,breeze将根据从OData服务接收的数据自动为您生成可观察的属性。并允许验证、跟踪更改、批量发送更改等等。
https://stackoverflow.com/questions/35150885
复制相似问题