如何清除以前访问视图时填充的observableArray的内容

编程入门 行业动态 更新时间:2024-10-22 02:46:21
本文介绍了如何清除以前访问视图时填充的observableArray的内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一个单页应用程序,该应用程序使用敲除进行数据绑定.我的单页应用程序中的CAApproval.html视图在视图模型代码中有一个名为AllCertificates的observablearray.它可以在页面上很好地填充.当您通过单击页面的navigation.html部分中的链接离开视图,然后返回到CAApproval页面时,先前访问的值仍在AllCertificates observableArray中,因此将显示在CAApproval视图中.

I have a Single Page Application that uses knockout for the data binding. The CAApproval.html view in my single page application has an observeablearray named AllCertificates in the viewmodel code. It populates fine on the page. When you navigate away from the view by clicking a link in the navigation.html part of the page and then return to CAApproval page, the values from the previouse visit are still in the AllCertificates observableArray and therefore are displayed on the CAApproval view.

每当用户返回使用该ObservableArray的CAApproval页面时,我需要清除AllCertificates observablearray的内容,以便如果用户离开该页面并返回,则observablearray的内容为null,因此没有数据屏幕上显示.这是我的视图模型代码的重点-

I need to clear the contents of the AllCertificates observablearray each time a user returns to the CAApproval page that uses that observablearray so that if a user leaves the page and comes back, the contents of the observablearray are null, and therefore no data is displayed on the screen. Here are the highlights of my viewmodel code-

define(['services/logger', 'durandal/system', 'durandal/plugins/router', 'services/CertificateDataService','controls/Lucas'], function(logger, system, router, CertificateDataService) { var allCertificates = ko.observableArray([]); var activate = function () { // go get local data, if we have it return SelectAllCerts(),SelectMyCerts(), GetCertificateDetails(), GetDDABankNums(); }; var vm = { activate: activate, allCertificates: allCertificates, SelectAllCerts: SelectAllCerts }); return vm; function SelectAllCerts() { return CertificateDataService.getallCertificates(allCertificates); } });

如何在用户每次访问该页面时清除observablearray的内容(在页面本身中导航时不是,仅当用户来自单独页面时才清除observablearray)?

How do I clear the contents of an observablearray each time the page a user comes to that page (NOT when navigating within the page itself, only clear the observablearray when the user comes from a seperate page)?

推荐答案

只需在您的激活函数(每次加载视图模型时都会调用它)中将其设置为等于空(allCertificates([]))-

Just set it equal to nothing (allCertificates([])) in your activate function, which is called each time your view model loads -

function(logger, system, router, CertificateDataService) { var allCertificates = ko.observableArray(); var activate = function () { allCertificates([]); // go get local data, if we have it return SelectAllCerts(),SelectMyCerts(), GetCertificateDetails(), GetDDABankNums(); }; var vm = { activate: activate, allCertificates: allCertificates, SelectAllCerts: SelectAllCerts });

更多推荐

如何清除以前访问视图时填充的observableArray的内容

本文发布于:2023-10-28 19:28:52,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1537571.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:视图   内容   observableArray

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!