简体   繁体   English

Ajax加载的数据不会更新布局

[英]Ajax loaded data doesn't update layout

I load data using ajax and populate my page using Knockout. 我使用ajax加载数据,并使用Knockout填充页面。 This all works great, when I changes pages to #contacts it looks good. 当我将页面更改为#contacts一切都很好。 However, I have a problem when the #contacts page is the initial page i load. 但是,当#contacts页面是我加载的初始页面时,我遇到了问题。 Eg if I load www.mydomain.com/#contacts , the initial page loaded is the list page, thus the ko.bindinghandlers.listview doesn't have any affect. 例如,如果我加载www.mydomain.com/#contacts ,则加载的初始页面是列表页面,因此ko.bindinghandlers.listview没有任何影响。 I tried re-creating the page, but that doesn't fully work either, not all the styles are applied as it should. 我尝试重新创建页面,但是那也不完全起作用,并非所有样式都应按应有的方式应用。 My list view is not just a list view, it contains a controllgroup as well, to make a list view with checkboxes. 我的列表视图不仅仅是一个列表视图,它还包含一个controllgroup,以使带有复选框的列表视图成为可能。

$("#contacts").page('destroy').page();

$('#contacts').bind('pageinit', function() {
    $('ul').listview();
});

How can I load data using Ajax, append it (using ko) to my ul and have it render correctly. 如何使用Ajax加载数据,将其附加(使用ko)到我的ul ,并使其正确呈现。

This is how it looks if #contacts is NOT the initial page loaded: 如果未将#contacts加载为初始页面,则外观#contacts 正确

This is the best result I manage to get this far, when #contacts IS the initial page loaded: #contacts是初始页面加载时,这是我设法达到的最好结果: 不正确的

You need to call refresh on your listview whenever your update it using JavaScript. 每当您使用JavaScript更新列表视图时,都需要在其上调用refresh

$('.selector').listview('refresh');

More on the docs . 有关文档的更多信息。

pageinit() probably doesn't get called when its the first load. pageinit()首次加载时可能不会被调用。 add a console.info there to make sure... if that's the issue, then just make sure it is being called on load() or whenever you feel like it. 在其中添加console.info以确保...如果这是问题所在,则只需确保在load()上或在您愿意时调用它即可。 was that it? 是吗

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM