Lightswitch 2013:在JS中保存然后刷新 [英] Lightswitch 2013: Save then Refresh in JS

查看:81
本文介绍了Lightswitch 2013:在JS中保存然后刷新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有2组代码:

  1. 保存数据

myapp.activeDataWorkspace.ProjectHandlerData.saveChanges();

myapp.activeDataWorkspace.ProjectHandlerData.saveChanges();

2.刷新页面

window.location.reload();

有没有一种方法可以使这两个按钮在一个按钮上一起工作,如当前,当我单击保存"时,浏览器会识别出更改,并且(您确定要离开页面)消息或类似内容弹出上..

is there a way to make both of these work together on one button, as currently when i click save, the browser recognizes the changes and the (are you sure you want to leave the page) message or something along those lines pops up..

欢呼

推荐答案

这是针对HTML客户端的,对吧? 假设是这种情况:

This is for the HTML client, right? Assuming that is the case:

saveChanges()是异步操作,因此您需要这样做:

saveChanges() is an asynchronous operation, so you'd want to do:

myapp.activeDataWorkspace.ProjectHandlerData.saveChanges().then(function () {
    window.location.reload();
});

这样,它将等到保存完更改后再重新加载屏幕.

That way it will wait until it is finished saving the changes before it reloads the screen.

但是,有一种更平滑的方法,至少从用户的角度来看,它更平滑. 在编辑屏幕上,省去Save方法,让LightSwitch处理该方法.当用户单击保存"时,它将关闭编辑屏幕,并返回到之前的位置.使用showScreen方法的options参数,我们可以更改该行为.

However, there is a smoother way to do it, at least from the user perspective it's smoother. On the edit screen, leave the Save method out, let LightSwitch handle that. When the user clicks save, it will close the edit screen, and go back to where they were before. Using the options parameter of the showScreen method, we can change that behavior.

按如下所示更改调用编辑屏幕的方法:

Change the method that calls the edit screen like this:

myapp.showEditProject(screen.Project, {
    afterClosed: function (editScreen) {
        myapp.showViewProject(editScreen.Project);
    }
});

这样,在关闭编辑屏幕并为您完成了保存更改操作之后,应用程序将自动导航到最近编辑的项目的详细信息视图屏幕.

This way, after the edit screen is closed, and it has handled the save changes operation for you, the application will automatically navigate to the details view screen of the recently edited item.

如果您想在添加新实体后刷新浏览屏幕:

If you are instead wanting to refresh the browse screen after adding a new entity:

myapp.showAddEditProject(null, {
    beforeShown: function (addEditScreen) {
        addEditScreen.Project = new myapp.Project();
    },
    afterClosed: function () {
        screen.Projects.load();
    }
});

这两个选项(beforeShown和afterClosed)为您提供了许多非常酷的功能,可以影响应用程序中的导航.

Those two options, beforeShown and afterClosed, give you a lot of really cool abilities to influence the navigation in your application.

这篇关于Lightswitch 2013:在JS中保存然后刷新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆