private-subnet 相关问题


如何从另一个 Sub 使用 KeyEventArgs 调用 Sub

我有两个替补 Private Sub kbHook_KeyDown(ByVal Key As System.Windows.Forms.Keys) 处理 KeyHook.KeyDown 和 Private Sub Form1_KeyPressCaps(ByVal key As Object, e As KeyEventArgs) 处理我。


TextChanged 事件搜索在我的代码中无法正常工作

private void dataGridView_MouseDoubleClick(对象发送者,MouseEventArgs e) { 状态文本框(真); btnUpdate.Enabled = true; btnDelete.Enabled = true; btnNew.En...


我想在不可组合的后台线程中调用可组合组件

会话管理器: 类 SessionManager @Inject 构造函数(@ApplicationContext private val context: Context) : 会话服务{ val openAlert = mutableStateOf(false) val Context.dataStore:


未遵循 Uvicorn 重新加载选项

我有三个目录:app、config和private 我在安装了 WatchFiles 的情况下以编程方式运行 uvicorn: uvicorn.run( “应用程序主:快”, 主机=主机,


为什么 File.ReadAllLinesAsync() 会阻塞 UI 线程?

这是我的代码。读取文件行的 WPF 按钮的事件处理程序: private async void Button_OnClick(对象发送者, RoutedEventArgs e) { Button.Content = "正在加载..."; 变种


Kotlin:辅助构造函数参数上不允许使用“val”

我有以下课程: 类 Person(值名称:字符串){ private var surname: String = "未知" 构造函数(名称:字符串,姓氏:字符串):this(名称){ this.姓氏 = 姓氏 ...


如何使用 python 从 Fetch/XHR 获取 Respose JSON 数据?

如果我在 https://lei-registrations.in/portal 的搜索框中搜索数据“ditech process Solutions private Limited”,那么如何使用 pyt 从 Fetch/XHR 获取响应 JSON 数据或请求 URL...


将值从用户控件传递到同一用户控件wpf c#中的另一个?

我有四个用户控件,我尝试将值从用户控件传递到另一个用户控件,这些用户控件存在于同一个用户控件中。 这个 xml 主页面 ` 我有四个用户控件,我尝试将值从用户控件传递到另一个用户控件,这些用户控件存在于同一个用户控件中。 这个 xml 主页面 ` <Grid> <StackPanel Background="#FFF"> <local:mwidget x:Name="mwidget" Loaded="UserControl1_Loaded"/> <local:addemploy x:Name="addemploy" Visibility="Hidden"/> <local:editemploy x:Name="editemploy" Visibility="Hidden" /> </StackPanel> </Grid>` 还有这个代码 ` private void UserControl1_Loaded(object sender, RoutedEventArgs e) { mwidget.ShowUserControl2Requested += OnShowUserControl2Requested; addemploy.ShowUserControl1Requested += OnShowUserControl1Requested; editemploy.ShowUserControl1Requestedd += ShowUserControl1Requestedd; mwidget.ShowUserControl2Requestedd += ShowUserControl1Requesteddd; } private void OnShowUserControl2Requested(object sender, EventArgs e) { addemploy.Visibility = Visibility.Visible; mwidget.Visibility = Visibility.Collapsed; } private void OnShowUserControl1Requested(object sender, EventArgs e) { mwidget.Visibility = Visibility.Visible; addemploy.Visibility = Visibility.Collapsed; } private void ShowUserControl1Requestedd(object sender, EventArgs e) { mwidget.Visibility = Visibility.Visible; editemploy.Visibility = Visibility.Collapsed; } private void ShowUserControl1Requesteddd(object sender, EventArgs e) { editemploy.Visibility = Visibility.Visible; mwidget.Visibility = Visibility.Collapsed; }` 这个代码mwidget ` public partial class mwidget : UserControl { public event EventHandler ShowUserControl2Requested; public event EventHandler ShowUserControl2Requestedd; public mwidget() { InitializeComponent(); } private void add_employ(object sender, RoutedEventArgs e) { ShowUserControl2Requested?.Invoke(this, EventArgs.Empty); } private void edit_employ(object sender, System.Windows.RoutedEventArgs e) { ShowUserControl2Requestedd?.Invoke(this, EventArgs.Empty); } }` 所以我想将值从 mwidget 传递到 editemploy,我尝试了一些解决方案,但不起作用 您需要在 mwidget 和 editemploy 中创建 DependencyPropertys 并将它们相互绑定。 (注意:在下面的示例中,我使用了 OneWayToSource。这可以防止 editemploy 更改 mwidget 中的值。如果您不想这样做,请将其更改为 TwoWay。) m小部件: public static readonly DependencyProperty MyValueProperty = DependencyProperty.Register( nameof(MyValue), typeof(bool), typeof(mwidget)); public bool MyValue { get => (bool)GetValue(MyValueProperty); set => SetValue(MyValueProperty, value); } 编辑雇佣: public static readonly DependencyProperty MyPassedValueProperty = DependencyProperty.Register( nameof(MyPassedValue), typeof(bool), typeof(editemploy)); public bool MyPassedValue { get => (bool)GetValue(MyPassedValueProperty); set => SetValue(MyPassedValueProperty, value); } xaml: <local:mwidget x:Name="mwidget" Loaded="UserControl1_Loaded"/> <local:addemploy x:Name="addemploy" Visibility="Hidden"/> <local:editemploy x:Name="editemploy" Visibility="Hidden" MyPassedValue="{Binding ElementName=mwidget, Path=MyValue, Mode=OneWayToSource}" />


npm 错误!该包已被标记为私有

我尝试在 npm 上发布我的 Angular 库。 但我收到错误 npm 错误!该包已被标记为私有。从 package.json 中删除“private”字段以发布它。 但我没有任何公关...


带有私有子的 VBA 代码处理时间太长

所以,我有 1903 行代码,这些代码合并在与 Private Sub Worksheet_Change (ByVal target As Range)一起使用的三个函数中。它们都工作得很好,但由于它是 1903 行,所以


Next.JS 有“仅客户端钩子”错误

我正在编写我的第一个 Next.JS 应用程序,并且在构建或部署时收到此错误: 预呈现页面“/”时发生错误 错误:useLocalStorage 是仅限客户端的挂钩 在 m (/private/var...


OSLogPrivacy:.private 和 .sensitive 之间有什么区别?

我正在使用 iOS 14 / macOS 11 中的新 os.log API 在我的应用程序中实现日志记录。 我刚刚注意到,当涉及到所包含变量的隐私时,我们有更多选择......


由于 Button 类的原因,无法处理来自键盘的事件。 JavaFX(已更改)

我正在使用javafx编写一个原始的java游戏。 我通过按下按钮来执行暂停功能 @FXML 私有按钮 btnPause; 暂停由字段 private boolean isPausethatchange...


在 .NET Framework 应用程序中使用 TableAdapter 更新数据失败

在 Visual studio 2022 中,我创建了一个 VB 表单,与 SQL 中的表连接。 我可以在表中添加新记录但不能更新。这是代码 Private Sub ButtonUpdate_Click(发送者作为对象,e作为


如何更改可编辑列表中重新排序图标的颜色?

我有一个可编辑的列表,其中可以重新订购哪些商品。我想更改重新排序颜色。怎么做? 结构虚拟列表:查看{ @State private var items = ["项目 1", "项目 2&


android中customView中如何收集Viewmodel StateFlow

android中customView中如何采集StateFlow 我有一个视图模型 类 MyViewModel : ViewModel() { 私有 val _myState = MutableStateFlow(MyState()) val myState:StateFlow android中customView中如何采集StateFlow 我有一个视图模型 class MyViewModel : ViewModel() { private val _myState = MutableStateFlow(MyState()) val myState: StateFlow<MyState> = _myState fun updateMyState(newState: MyState) { _myState.value = newState } } data class MyState( val name: String = "", val age: Int = 0, val isMarried: Boolean = false ) 我能够使用收集活动中的更新数据 lifecycleScope.launchWhenStarted { viewModel.myState.collect { state -> Log.e("collected ", "tateflow: ${state.name}") } } 我们如何根据收集的数据更新自定义视图?我们如何根据这些数据更新自定义视图 您能分享一下在自定义视图中创建 viewModel 的代码吗?你的代码是不是类似这样: private val viewModel: ActivityViewModel by activityViewModels()


Velocity 在 Spring Boot 中找不到模板资源

我使用 Velocity 模板引擎在我的 Spring boot 应用程序中使用电子邮件模板发送电子邮件实用程序。 当前的代码如下所示。 pom.xml: 我正在使用 Velocity 模板引擎在我的 Spring boot 应用程序中使用电子邮件模板发送电子邮件实用程序。 当前代码如下所示。 pom.xml: <dependency> <groupId>org.apache.velocity</groupId> <artifactId>velocity</artifactId> <version>1.7</version> </dependency> <dependency> <groupId>org.apache.velocity</groupId> <artifactId>velocity-tools</artifactId> <version>2.0</version> </dependency> 速度引擎 bean 配置: @Configuration public class VelocityConfig { @Bean public VelocityEngine velocityEngine() { VelocityEngine ve = new VelocityEngine(); ve.setProperty(RuntimeConstants.RESOURCE_LOADER, "classpath"); ve.setProperty("classpath.resource.loader.class", ClasspathResourceLoader.class.getName()); ve.init(); return ve; } } 电子邮件模板放置在 src/main/resources/email-templates/summary-email.vm <!DOCTYPE html> <head> <title>Summary</title> </head> <body> <h1>Claims Summary</h1> </body> </html> 放置在以下目录中: src ├── main │ ├── java │ │ └── com │ │ └── packageNameioot │ │ └── SpringBootApplication.java │ ├── resources │ │ ├── email-templates │ │ │ └── summary-email.vm │ │ └── application.properties 使用模板发送电子邮件的服务类: @Slf4j @Service @RequiredArgsConstructor public class EmailSummaryService { private final EmailConnector connector; private final VelocityEngine velocityEngine; public Mono<Void> sendFinanceClaimsRunEmailSummary(FinancePeriodRunEntity periodRunEntity, int successCount, int errorCount) { EmailDto emailDto = EmailDto.builder() .recipients(Set.of("[email protected]")) .subject("Claims summary") .body(createEmailBody()) .html(true) .build(); return connector.submitEmailRequest(emailDto); } private String createEmailBody() { VelocityContext context = new VelocityContext(); Template template = velocityEngine.getTemplate("email-templates/summary-email.vm"); StringWriter writer = new StringWriter(); template.merge(context, writer); return writer.toString(); } } 但是Velocity无法定位模板,出现以下错误。 ERROR velocity:96 - ResourceManager : unable to find resource 'email-templates/summary-email.vm' in any resource loader. org.apache.velocity.exception.ResourceNotFoundException: Unable to find resource 'email-templates/summary-email.vm' 属性应该这样设置: VelocityEngine ve = new VelocityEngine(); ve.setProperty(RuntimeConstants.RESOURCE_LOADER, "classpath"); ve.setProperty("resource.loader.classpath.class", ClasspathResourceLoader.class.getName()); 根据 Apache Velocity Engine 文档。


.NET MAUI:自定义Shell TitleView并绑定到当前页面标题

我想用我自己的自定义布局替换默认的 Shell 标头,如下所示: 我想用我自己的自定义布局替换默认的 Shell 标头,如下所示: <?xml version="1.0" encoding="UTF-8" ?> <Shell x:Class="MyNamespace.App.AppShell" xmlns="http://schemas.microsoft.com/dotnet/2021/maui" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" xmlns:local="clr-namespace:MyNamespace.App" xmlns:pages="clr-namespace:MyNamespace.App.Pages" BindingContext="{x:Static local:MainView.Instance}" Shell.FlyoutBehavior="{Binding ShellFlyoutType}" x:Name="shellMain"> <Shell.TitleView> <Grid ColumnDefinitions="*,200"> <Label BindingContext="{x:Reference shellMain}" Text="{Binding Path=CurrentPage.Title, Mode=OneWay}" FontSize="Large" TextColor="White" /> <ActivityIndicator IsRunning="{Binding IsBusy}" Color="Orange" Grid.Column="1" HorizontalOptions="End" /> </Grid> </Shell.TitleView> <ShellContent Title=" Login" ContentTemplate="{DataTemplate local:MainPage}" Route="login" FlyoutItemIsVisible="False" /> <ShellContent Title="Dashboard" ContentTemplate="{DataTemplate pages:DashboardPage}" Route="dashboard" /> </Shell> 我无法绑定当前页面标题。 我的 AppShell.xaml Shell 声明如下 <Shell ... x:Name="shellMain"> 作为替代方案,您可以在 OnNaviged 方法中设置 titleview : 在 AppShell.xaml 中,定义标签的名称 <Shell.TitleView> <Grid ColumnDefinitions="*,200"> <Label BindingContext="{x:Reference shellMain}" x:Name="mylabel" FontSize="Large" TextColor="White" /> <ActivityIndicator IsRunning="{Binding IsBusy}" Color="Orange" Grid.Column="1" HorizontalOptions="End" /> </Grid> </Shell.TitleView> 在AppShell.xaml.cs中,重写OnNaviged方法,获取当前项目 protected override void OnNavigated(ShellNavigatedEventArgs args) { base.OnNavigated(args); var shellItem = Shell.Current?.CurrentItem; string title = shellItem?.Title; int iterationCount = 0; while (shellItem != null && title == null) { title = shellItem.Title; shellItem = shellItem.CurrentItem; if (iterationCount > 10) break; // max nesting reached iterationCount++; } myLabel.Text = title; } 希望它对你有用。 我正在尝试同样的方法来修改 TitleView 的外观。它可以在 iOS 上运行,尽管那里还有另一个错误。但在 Android 上我遇到了同样的问题。在前进导航中,它会更新标题,但当您按后退按钮时,标题不会更新。我已经打开了一个问题并添加了一个存储库。 https://github.com/dotnet/maui/issues/12416#issuecomment-1372627514 还有其他方法可以修改TitleView的外观吗? 我使用视图模型开发了这个解决方法,主要不是为了提供 MVVM 解决方案,而是因为其他建议的答案对我不起作用。 (我怀疑 Liqun Shen 2 月 15 日针对他自己的问题的评论中的建议会起作用。但我没有注意到这一点,直到我自己修复)。 当前页面的标题保存在可由 shell 的视图模型和每个内容页面的视图模型访问的类中: public class ServiceHelper { private static ServiceHelper? _default; public static ServiceHelper Default => _default ??= new ServiceHelper(); internal string CurrentPageTitle { get; set; } = string.Empty; } shell 中每个内容页面的视图模型提供其页面标题。为了促进这一点,大部分工作都是由基本视图模型完成的,它们都是从该模型派生而来的: public abstract class ViewModelBase(string title) : ObservableObject { private ServiceHelper? _serviceHelper; public string Title { get; } = title; internal ServiceHelper ServiceHelper { get => _serviceHelper ??= ServiceHelper.Default; set => _serviceHelper = value; // For unit testing. } public virtual void OnAppearing() { ServiceHelper.CurrentPageTitle = Title; } } 每个 shell 内容页面视图模型只需要让其基础视图模型知道它的标题: public class LocationsViewModel : ViewModelBase { public LocationsViewModel() : base("Locations") { } } 每个 shell 内容页面都需要在其视图模型中触发所需的事件响应方法: public partial class LocationsPage : ContentPage { private LocationsViewModel? _viewModel; public LocationsPage() { InitializeComponent(); } private LocationsViewModel ViewModel => _viewModel ??= (LocationsViewModel)BindingContext; protected override void OnAppearing() { base.OnAppearing(); ViewModel.OnAppearing(); } } Shell 的视图模型为标题栏提供当前页面的标题: public class AppShellViewModel() : ViewModelBase(Global.ApplicationTitle) { private string _currentPageTitle = string.Empty; public string CurrentPageTitle { get => _currentPageTitle; set { _currentPageTitle = value; OnPropertyChanged(); } } public void OnNavigated() { CurrentPageTitle = ServiceHelper.CurrentPageTitle; } } Shell 需要在其视图模型中触发所需的事件响应方法: public partial class AppShell : Shell { private AppShellViewModel? _viewModel; public AppShell() { InitializeComponent(); } private AppShellViewModel ViewModel => _viewModel ??= (AppShellViewModel)BindingContext; protected override void OnNavigated(ShellNavigatedEventArgs args) { base.OnNavigated(args); ViewModel.OnNavigated(); } } 最后,Shell 的 XAML 在标题栏/导航栏上显示由 Shell 视图模型提供的当前页面的标题: <Shell.TitleView> <HorizontalStackLayout VerticalOptions="Fill"> <Image Source="falcon_svg_repo_com.png" HeightRequest="50"/> <Label x:Name="CurrentPageTitleLabel" Text="{Binding CurrentPageTitle}" FontSize="24" Margin="10,0" VerticalTextAlignment="Center"/> </HorizontalStackLayout> </Shell.TitleView>


无法访问派生模板类中模板基类的成员[重复]

我有一个模板基类。可以说。 模板 类基类 { 私人的: int成员1; 字符成员2; .... }; 我从上面的类派生了另一个类。 模板 我有一个模板基类。可以说。 template<class KeyF> class Base { private: int member1; char member2; .... }; 我从上面的类派生了另一个类。 template<class KeyF> class Derived : public Base<KeyF> { public: void func1() { <accessing member1/member2> } .... }; 上面的代码不能在 gcc 中编译。说明 member1 不是 Derived 的成员。但它已经从基类派生了,那为什么它不能访问它的成员呢? 您需要在基本成员名称前添加 this-> 或 Base<KeyF>:: 前缀,或者向类添加 using 声明以取消隐藏它们。他们的名字是从属名称,并且是隐藏的。 Base中的成员是private。您无法在本课程之外访问课程的 private members(friend 除外)。让它们 protected,或者让 protected getters。 您尝试过受保护吗?自从我深入 C++ 以来已经有一段时间了... 我认为解决这个问题需要两个改变: 在基类中,将成员定义为“受保护”而不是“私有”,以便在派生类中可访问。 在派生类中,在受保护成员前面添加基类名称。在这种情况下,它应该看起来像“Base::member1”。 在我的例子中使用 C++17 标准,问题得到了解决。希望这有帮助。感谢 Kerrek SB 提供的信息。


将属性值从父级用户控件传递到子级的 DependencyProperty

如何将属性(SomeProperty)从ParentUserControl上下文传递到ChildUserControl的DependencyProperty(MyDProperty)? 在 XAML 中,它应该是: 如何将 ParentUserControl 上下文中的 property (SomeProperty) 传递到 ChildUserControl 的 DependencyProperty (MyDProperty)? 在XAML中,应该是: 但是,由于某种原因,MyDProperty 永远不会使用 Parent.DataContext.SomeProperty 设置。 就我而言,我正在传递一个操作,但这并不重要。我认为问题出在绑定上。 家长用户控制: public Action RemoveEsl1 => throw new NotImplementedException(); <uc:ChildUserControl Title="ESL 1" RemoveEslAction="{Binding RemoveEsl1}" DataContext="{Binding Esl1}"/> 子用户控件: public static readonly DependencyProperty RemoveEslActionProperty = DependencyProperty.Register(nameof(RemoveEslAction), typeof(Action), typeof(ChildUserControl), new PropertyMetadata(delegate { })); public Action RemoveEslAction { get => (Action)GetValue(RemoveEslActionProperty); set => SetValue(RemoveEslActionProperty, value); } 我在这里找到了各种技巧,但没有一个适合我或有效。 回答我自己的问题(检查 ParentUserControl): 型号: public class RootModel : ViewModelBase { private ParentModel parentModel = new(); public ParentModel ParentModel { get => parentModel; set => RisePropertyChanged(ref parentModel, value); } } public class ParentModel : ViewModelBase { private ChildModel childModel = new(); public ChildModel ChildModel { get => childModel; set => RisePropertyChanged(ref childModel, value); } public string ParentModelProperty => "Correct value from ParentModel"; } public class ChildModel : ViewModelBase { private string childModelProperty = "Wrong default value from ChildModel"; public string ChildModelProperty { get => childModelProperty; set => RisePropertyChanged(ref childModelProperty, value); } } 主窗口: <Window.DataContext> <model:RootModel/> </Window.DataContext> <uc:ParentUserControl DataContext="{Binding ParentModel}"/> 家长用户控件: <uc:ChildUserControl ChildDependency="{Binding DataContext.ParentModelProperty, RelativeSource={RelativeSource AncestorType=UserControl}}" DataContext="{Binding ChildModel}"/> 子用户控件: <StackPanel> <Label Content="Dependency property:"/> <Label Content="{Binding ChildDependency, RelativeSource={RelativeSource AncestorType=UserControl}}"/> <Separator/> <Label Content="Property:"/> <Label Content="{Binding ChildModelProperty}"/> </StackPanel> public partial class ChildUserControl : UserControl { public static readonly DependencyProperty ChildDependencyProperty = DependencyProperty.Register(nameof(ChildDependency), typeof(string), typeof(ChildUserControl), new ("Wrong default DP value from ChildUserControl")); public string ChildDependency { get => (string)GetValue(ChildDependencyProperty); set => SetValue(ChildDependencyProperty, value); } public ChildUserControl() { InitializeComponent(); } } 这就是如何将属性 (SomeProperty) 从 ParentUserControl 上下文传递到 ChildUserControl 的 DependencyProperty (MyDProperty)。


如果类型是从变量进行数据绑定,则通过 <object> 标签在 Angular 中显示 pdf 无法在 Chrome 中工作

我正在尝试通过 标签在 Chrome 中显示 pdf。 如果我手动编写类型,它会起作用: 不工作 但是... 我正在尝试通过 <object> 标签在 Chrome 中显示 pdf。 如果我手动写 type: 就可以了 <object [data]="getUrl(true)" type="application/pdf"> Not working </object> 但如果我从变量读取类型则不会: <object [data]="getUrl(true)" [type]="file.mimeType"> Not working </object> 为什么?这是一些非常奇怪的错误,还是我做错了什么可怕的事情。 这里是plunkr。 它可以在 Firefox 中运行(所有 4 个对象都会显示),但不能在 Chrome 中运行 (Version 74.0.3729.169 (Official Build) (64-bit)): 我遇到了同样的问题,但我不明白原因。 就我而言,我决定在基于 Blink 引擎的浏览器中使用“embed”元素而不是“object”元素。 <ng-template #blinkPlatformViewer> <embed [src]="getUrl(true)" [type]="file.mimeType"/> </ng-template> <object *ngIf="!isBlinkPlatform; else blinkPlatformViewer" [data]="getUrl(true)" [type]="file.mimeType"> Not working </object> import { Platform } from '@angular/cdk/platform'; import { DomSanitizer, SafeResourceUrl } from '@angular/platform-browser'; export class FileContentComponent { constructor(private readonly sanitizer: DomSanitizer, private readonly platform: Platform) { } get isBlinkPlatform(): boolean { return this.platform.BLINK; } }


通过更少的 Java API 调用来映射 Google 云端硬盘内容的有效方法

大家好,我有一个代码,用于列出共享驱动器中存在的文件(以便稍后下载并创建相同的文件夹路径) 目前我做这样的事情: 哈希映射 大家好,我有一个代码,用于列出共享驱动器中存在的文件(以便稍后下载并创建相同的文件夹路径) 目前我正在做这样的事情: HashMap<String, Strin> foldersPathToID = new HashMap<>(); //searching all folders first saving their IDs searchAllFoldersRecursive(folderName.trim(), driveId, foldersPathToID); //then listing files in all folders HashMap<String, List<File>> pathFile = new HashMap<>(); for (Entry<String, String> pathFolder : foldersPathToID.entrySet()) { List<File> result = search(Type.FILE, pathFolder.getValue()); if (result.size() > 0) { String targetPathFolder = pathFolder.getKey().trim(); pathFile.putIfAbsent(targetPathFolder, new ArrayList<>()); for (File file : result) { pathFile.get(targetPathFolder).add(file); } } } 递归方法在哪里: private static void searchAllFoldersRecursive(String nameFold, String id, HashMap<String, String> map) throws IOException, RefreshTokenException { map.putIfAbsent(nameFold, id); List<File> result; result = search(Type.FOLDER, id); // dig deeper if (result.size() > 0) { for (File folder : result) { searchAllFoldersRecursive(nameFold + java.io.File.separator + normalizeName(folder.getName()), folder.getId(), map); } } } 搜索功能是: private static List<com.google.api.services.drive.model.File> search(Type type, String folderId) throws IOException, RefreshTokenException { String nextPageToken = "go"; List<File> driveFolders = new ArrayList<>(); com.google.api.services.drive.Drive.Files.List request = service.files() .list() .setQ("'" + folderId + "' in parents and mimeType" + (type == Type.FOLDER ? "=" : "!=") + "'application/vnd.google-apps.folder' and trashed = false") .setPageSize(100).setFields("nextPageToken, files(id, name)"); while (nextPageToken != null && nextPageToken.length() > 0) { try { FileList result = request.execute(); driveFolders.addAll(result.getFiles()); nextPageToken = result.getNextPageToken(); request.setPageToken(nextPageToken); return driveFolders; } catch (TokenResponseException tokenError) { if (tokenError.getDetails().getError().equalsIgnoreCase("invalid_grant")) { log.err("Token no more valid removing it Please retry"); java.io.File cred = new java.io.File("./tokens/StoredCredential"); if (cred.exists()) { cred.delete(); } throw new RefreshTokenException("Creds invalid will retry re allow for the token"); } log.err("Error while geting response with token for folder id : " + folderId, tokenError); nextPageToken = null; } catch (Exception e) { log.err("Error while reading folder id : " + folderId, e); nextPageToken = null; } } return new ArrayList<>(); } 我确信有一种方法可以通过很少的 api 调用(甚至可能是一个调用?)对每个文件(使用文件夹树路径)进行正确的映射,因为在我的版本中,我花了很多时间进行调用 service.files().list().setQ("'" + folderId+ "' in parents and mimeType" + (type == Type.FOLDER ? "=" : "!=") + "'application/vnd.google-apps.folder' and trashed = false").setPageSize(100).setFields("nextPageToken, files(id, name)"); 每个子文件夹至少一次......并且递归搜索所有内容需要很长时间。最后,映射比下载本身花费的时间更多...... 我搜索了文档,也在此处搜索,但没有找到任何内容来列出具有一个库的所有驱动器调用任何想法? 我想使用专用的 java API 来获取共享 GoogleDrive 中的所有文件及其相对路径,但调用次数尽可能少。 提前感谢您的时间和答复 我建议您使用高效的数据结构和逻辑来构建文件夹树并将文件映射到其路径,如下所示 private static void mapDriveContent(String driveId) throws IOException { // HashMap to store folder ID to path mapping HashMap<String, String> idToPath = new HashMap<>(); // HashMap to store files based on their paths HashMap<String, List<File>> pathToFile = new HashMap<>(); // Fetch all files and folders in the drive List<File> allFiles = fetchAllFiles(driveId); // Build folder path mapping and organize files for (File file : allFiles) { String parentId = (file.getParents() != null && !file.getParents().isEmpty()) ? file.getParents().get(0) : null; String path = buildPath(file, parentId, idToPath); if (file.getMimeType().equals("application/vnd.google-apps.folder")) { idToPath.put(file.getId(), path); } else { pathToFile.computeIfAbsent(path, k -> new ArrayList<>()).add(file); } } // Now, pathToFile contains the mapping of paths to files // Your logic to handle these files goes here } private static List<File> fetchAllFiles(String driveId) throws IOException { // Implement fetching all files and folders here // Make sure to handle pagination if necessary // ... } private static String buildPath(File file, String parentId, HashMap<String, String> idToPath) { // Build the file path based on its parent ID and the idToPath mapping // ... }


hasSystemFeature(PackageManager.FEATURE_CAMERA) 对于没有相机的设备返回 true

我有一个使用相机功能的应用程序,但其部分功能也可以在没有相机功能的情况下运行。所以我已将其放入我的清单中。 我有一个使用相机功能的应用程序,但其部分功能也可以在没有相机功能的情况下运行。所以我已将其放入我的清单中。 <uses-permission android:name="android.permission.CAMERA" /> <uses-feature android:name="android.hardware.camera" android:required="false"/> 在我的代码中,我使用此功能检查设备是否有摄像头 final boolean deviceHasCameraFlag = pm.hasSystemFeature(PackageManager.FEATURE_CAMERA); 现在我正在运行 Android 4.0(ICS) 并且没有摄像头的平板电脑上测试我的代码。但我仍然得到 deviceHasCameraFlag 的真实值。这很奇怪还是我错过了什么? 我尝试了不同的方法,甚至在蓝牙功能上尝试了相同的方法,因为平板电脑甚至没有蓝牙功能。它适用于蓝牙,但适用于相机。 它是什么设备?你得到的答案是一个错误,4.0 现在已经很老了。许多仍然运行此版本的平板电脑制作不正确,硬件和软件都存在多个问题。 无论如何,您应该始终准备好处理 Camera.open() 或 Camera.open(0) 上的故障:例如,在某些情况下,设备上的其他软件不会正常释放相机。 因此,在您的情况下,您有误报,您尝试打开相机,但失败了,并且您继续,就像设备上没有相机一样,即使PackageManager认为PackageManager.FEATURE_CAMERA可用。 虽然我已经接受了 Alex 的答案,但我想把这个答案放在这里,展示如何处理硬件故障和错误。 我的发现是在我的低标准 Android 设备的情况下 pm.hasSystemFeature(PackageManager.FEATURE_CAMERA) 即使相机不存在并且似乎是设备错误,也会返回 true。 所以每当有场景需要检查设备上是否存在摄像头时,请参考下面的解决方案来了解如何处理此类故障 int numberOfCameras = Camera.getNumberOfCameras(); context = this; PackageManager pm = context.getPackageManager(); final boolean deviceHasCameraFlag = pm.hasSystemFeature(PackageManager.FEATURE_CAMERA); if( !deviceHasCameraFlag || numberOfCameras==0 ) { Log.e(TAG, "Device has no camera" + numberOfCameras); Toast.makeText(getApplicationContext(), "Device has no camera", Toast.LENGTH_SHORT).show(); captureButton.setEnabled(false); } else { Log.e(TAG, "Device has camera" + deviceHasCameraFlag + numberOfCameras); } 在此,我要检查摄像头的数量以及设备是否具有摄像头功能布尔值,因此即使系统返回一个不正确的值,另一个条件也将有助于纠正代码。 就我而言,我有以下代码: public boolean hasCameraSupport() { boolean hasSupport = false; if(getPackageManager().hasSystemFeature(PackageManager.FEATURE_CAMERA_ANY)) { //<- this constant caused problems hasSupport = true; } return hasSupport; } 并且它在运行 Android 4.1.1 (API 16) 的 Genymotion 设备上不断返回 false。一旦我将常数 PackageManager.FEATURE_CAMERA_ANY 更改为 PackageManager.FEATURE_CAMERA,我的问题就消失了。我猜测并非所有设备/API 级别都支持PackageManager.FEATURE_CAMERA_ANY。 我明白了,你一定会尝试这个,它肯定会起作用...... import android.hardware.Camera; int numCameras = Camera.getNumberOfCameras(); if (numCameras > 0) { System.out.println("camera"); } else { System.out.println("No Camera"); } 对于CameraX,如果设备上没有Camera时FEATURE_CAMERA_ANY方法仍然返回true,您可以添加以下方法。因此,当 CameraX 初始化时,无论 FEATURE_CAMERA_ANY 返回 true 还是 false,如果相机实际上在设备上不可用,下面的方法将确保执行您想要的操作。 private CameraSelector cameraSelector; private ProcessCameraProvider cameraAvailableCheck; private ListenableFuture<ProcessCameraProvider> cameraAvailableCheckFuture; private void checkIfAnyCameraExist() { cameraAvailableCheckFuture = ProcessCameraProvider.getInstance(context); cameraAvailableCheckFuture.addListener(new Runnable() { @Override public void run() { try { cameraAvailableCheck = cameraAvailableCheckFuture.get(); if ((cameraAvailableCheck.hasCamera(cameraSelector.DEFAULT_BACK_CAMERA) || cameraAvailableCheck.hasCamera(cameraSelector.DEFAULT_FRONT_CAMERA) )) { //Do what you want if at least back OR front camera exist } else { //Do what you want if any camera does not exist } } catch (ExecutionException | InterruptedException | CameraInfoUnavailableException e) { // No errors need to be handled for this Future. // This should never be reached. } } }, ContextCompat.getMainExecutor(this)); } 请尝试此代码: private boolean isDeviceSupportCamera() { if (getApplicationContext().getPackageManager().hasSystemFeature( PackageManager.FEATURE_CAMERA)) { // this device has a camera return true; } else { // no camera on this device return false; } } 还是不行请告诉我


活动深层链接 - IllegalArgumentException:缺少必需的参数并且没有 android:defaultValue

在我的应用程序中,我有以下结构: 在我的应用程序中,我具有以下结构: <!-- AndroidManifest.xml --> <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android"> <application> <activity android:name=".DeepLinkActivity" android:exported="true" android:launchMode="singleInstancePerTask"> <intent-filter> <action android:name="android.intent.action.VIEW" /> <category android:name="android.intent.category.DEFAULT" /> <category android:name="android.intent.category.BROWSABLE" /> <data android:host="myhost" android:path="/mypath" android:scheme="myscheme" /> </intent-filter> </activity> </application> </manifest> <!-- activity_deep_link.xml --> <?xml version="1.0" encoding="utf-8"?> <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent"> <androidx.fragment.app.FragmentContainerView android:id="@+id/navHostFragment" android:name="androidx.navigation.fragment.NavHostFragment" android:layout_width="match_parent" android:layout_height="match_parent" app:defaultNavHost="true" tools:navGraph="@navigation/my_nav_graph" /> </FrameLayout> // DeepLinkActivity.kt class DeepLinkActivity : AppCompatActivity() { private lateinit var binding: ActivityDeepLinkBinding override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) binding = ActivityDeepLinkBinding.inflate(layoutInflater) setContentView(binding.root) setUpNavigationGraph() } private fun setUpNavigationGraph() { val navHostFragment = supportFragmentManager .findFragmentById(binding.navHostFragment.id) as NavHostFragment val navController = navHostFragment.navController val navGraph = navController.navInflater .inflate(R.navigation.my_nav_graph) .apply { this.setStartDestination(R.id.notTheStartDestinationFragment) } val startDestinationArgs = bundleOf( "someRequiredArgumentHere" to false ) navController.setGraph(navGraph, startDestinationArgs) } } 当我通过 ADB (adb shell am start -d myscheme://myhost/mypath) 通过深度链接打开该活动时,该活动正常启动。 但是当我通过 Chrome 应用程序启动它时,应用程序崩溃了: 原因:java.lang.IllegalArgumentException:缺少必需参数“someRequiredArgumentHere”并且没有 android:defaultValue 观察:我正在使用 Safe Args 插件。 我做错了什么以及为什么行为不同? 我刚刚发现为什么在通过浏览器导航时会忽略 startDestinationArgs。 如果我们检查NavController#setGraph(NavGraph, Bundle?)的内部代码,如果没有发生深层链接,NavController#onGraphCreated(Bundle?)只会使用startDestinationArgs。 作为一种解决方法,在设置导航图之前,我只需清除活动的意图(但这可能不是解决该问题的最佳方法)


如何使用 Xamarin 立即用点屏蔽密码字符

我想消除在 Xamarin.Forms 中输入密码时的延迟。我在互联网上没有找到任何解决方案。 我想消除在 Xamarin.Forms 中输入密码时的延迟。我在网上没有找到任何解决方案。 <local:NoDelayEntry x:Name="passwordEntry" Placeholder="Password" /> class NoDelayEntry : Entry { public NoDelayEntry() : base() { this.TextChanged += OnEntryTextChanged; } private void OnEntryTextChanged(object sender, TextChangedEventArgs e) { // Customize the behavior as needed this.IsPassword = true; this.Text = new string('●', e.NewTextValue.Length); } } 到目前为止我已经尝试过以下操作;但是,当我登录时,原始密码文本被替换为“●”。有没有办法在保留原始密码的同时仍然使用屏蔽行为? 一种想法是使用一个标签来遮盖密码字段,该标签会更新以显示键入的点数,但我不确定如何保持标签下方的密码字段可选。


具有 TimestampableEntity 特征的实体在 PUT 操作中失败

我正在全新安装 API Platform (v3.2.7),并且使用 Gedmo\Timestampable\Traits\TimestampableEntity 这是我的实体(问候语示例) 我正在全新安装 API Platform (v3.2.7),并且正在使用 Gedmo\Timestampable\Traits\TimestampableEntity 这是我的实体(问候语示例) <?php namespace App\Entity; use ApiPlatform\Metadata\ApiResource; use Doctrine\ORM\Mapping as ORM; use Symfony\Component\Validator\Constraints as Assert; use Gedmo\Timestampable\Traits\TimestampableEntity; #[ApiResource] #[ORM\Entity] class Greeting { use TimestampableEntity; #[ORM\Id] #[ORM\Column(type: "integer")] #[ORM\GeneratedValue] private ?int $id = null; #[ORM\Column] #[Assert\NotBlank] public string $name = ""; public function getId(): ?int { return $this->id; } } 和我的 config/services.yaml gedmo.listener.timestampable: class: Gedmo\Timestampable\TimestampableListener tags: - { name: doctrine.event_listener, event: 'prePersist' } - { name: doctrine.event_listener, event: 'onFlush' } - { name: doctrine.event_listener, event: 'loadClassMetadata' } 它在 POST 操作上工作正常,但在执行 PUT 时失败。我收到此错误 执行查询时发生异常:SQLSTATE[23000]: 完整性约束违规:1048 列“created_at”不能 空 我使用的版本是:symfony 6.4.1,doctrine 2.12,gedmo 3.14 我最终做的是使用 PATCH 而不是 PUT。所以我可以编辑部分实体,并且特征仍然更新 updated_at 字段


使用 IndexedPointInAreaLocator 和 STRTree(JTS 拓扑套件)无法实现多边形中的点性能

私人列表findZonesForShipPosition(点点){ List zoneDefinitionCacheHits = new ArrayList<>(); strTree.query(point.getEnvelopeIn... private List<ZoneDefinitionCacheMemory> findZonesForShipPosition(Point point) { List<Object> zoneDefinitionCacheHits = new ArrayList<>(); strTree.query(point.getEnvelopeInternal(), zoneDefinitionCacheHits::add); return zoneDefinitionCacheHits.stream() .filter(ZoneDefinitionCacheMemory.class::isInstance) .map(ZoneDefinitionCacheMemory.class::cast) .filter(zoneDefinition -> isPointInsideGeometry(point, zoneDefinition.getGeometry())) .toList(); } private boolean isPointInsideGeometry(Point point, Geometry geometry) { PointOnGeometryLocator pointOnGeometryLocator = new IndexedPointInAreaLocator(geometry); int location = pointOnGeometryLocator.locate(point.getCoordinate()); boolean isInside = location == Location.INTERIOR; return isInside; } 我使用上面的代码来搜索多边形中的点,在查询之前将所有多边形和多边形插入到 strTree 中,并且我还使用 IndexedPointInAreaLocator 在 STR Tree 的顶部添加一个附加过滤器来验证是否给定点是否确实位于几何中。 此外,我的多边形非常大,这意味着某些多边形中有近 160 万个点。 因此,通过此实现,我面临着性能问题,这种方法至少需要 100 毫秒才能完成,这对于我的用例来说是不期望的。 这里可能出现什么问题?或任何以某种方式加快速度的建议。 我的用例:我将获得很多点来检测它们是否位于给定几何形状(多边形和多多边形)的内部或外部 我尝试使用 Polygon.contains(point) 谓词,但它比 IndexedPointInAreaLocator 方法花费更多时间。 如果你的多边形很大(从某种意义上说它们覆盖了很大的区域)或者形状很奇怪。然后,细分它们可能会提高索引性能,请记住索引首先在多边形的边界框上工作,以节省在多边形测试中进行昂贵的点。如果一个点落入许多边界框但只有一个多边形,则索引不会有太大帮助。 Paul Ramsey 的这篇博客文章在 PostGIS 上下文中讨论了这一点,但这里的底层实现是相同的。这个answer将帮助您划分多边形(因为我认为JTS没有细分方法)。 您还可以从 JTS 代码周围使用 GeoTools 中受益,因为这将允许您切换到使用具有内置索引的 PostGIS 或 GeoPackage 数据库,或更简单的 在内存存储中建立索引。


如何使用 blazor <InputDate /> 标签使用当地文化来格式化日期

我正在我的 Blazor 应用程序中使用该标签。但是我如何使用我自己的文化来格式化日期? 我正在我的 Blazor 应用程序中使用该标签。但是我如何使用我自己的文化来格式化日期? <InputDate class="form-control" @bind-Value="@ValidDate" @bind-Value:culture="nl-BE" @bind-Value:format="dd/MM/yyyy" /> 问候 迪特尔 答案是@bind-Value:format,就像这样 @page "/" <EditForm Model="@CurrentPerson"> <InputDate @bind-Value="@CurrentPerson.DateOfBirth" @bind-Value:format="dd/MM/yyyy"/> </EditForm> @code { Person CurrentPerson = new Person(); public class Person { public DateTime DateOfBirth { get; set; } = DateTime.Now; } } 还可以选择使用bind-Value:culture。 无法设置InputDate或<input type="date">的格式。这取决于浏览器设置。用户可以更改浏览器的语言。但您无法从 HTML 更改它。如果您确实需要自定义格式,则必须使用InputText或<input type="text">。我建议使用一些 javascript 库,例如 jQuery UI datepicker。 该解决方案对我不起作用。我是这样工作的: @代码{ 仅私人日期? _geboortedatum; private string GeboortedatumFormatted { get => _geboortedatum?.ToString("dd-MM-yyyy") ?? ""; set { if (DateOnly.TryParse(value, out var newDate)) { _geboortedatum = newDate; } } } } 地质学 _geboortedatum" class="text-danger" />


为什么我在GWT中无法隐藏UiBinder中的DialogBox?

在 Test.ui.xml 中 测试 一些小部件.. 在Test.ui.xml <g:DialogBox ui:field="wishlistDialogBox" autoHide="true"> <g:caption>Test</g:caption> <g:HTMLPanel> some widgets..</g:HTMLPanel> </g:DialogBox> 运行后,应用程序仍然显示DialogBox,所以我尝试在TestView.java中为“wishlistDialogBox”设置隐藏,但没有成功。 @UiField DialogBox wishlistDialogBox; @Inject public TestView(final Binder binder) { widget = binder.createAndBindUi(this); wishlistDialogBox.hide(); } 然后我在TestPresenter.java中为它设置了隐藏,但仍然不起作用 @Override protected void onBind() { super.onBind(); getView().getWishlistDialogBox().hide(); } 怎么了,古德尔根本没有解释。 另外,DialogBox如何重复使用? 当谈论将它们添加到 DOM 时,DialogBox(以及一般的 PopupPanel)不像任何其他小部件那样工作。您永远不应该像以前那样将它们直接附加到它(即 panel.add(yourDialogBox) 或在 UiBinder XML 文件中)。相反,您应该创建它们,然后简单地调用 hide()/show() 以及类似的方法,以使其显示/隐藏(即,在 DOM 的末尾附加/分离)。 对我有用的是与任何其他小部件分开创建一个对话框。所以它有自己的 Java 文件和自己的 ui.xml 文件: UiBinder xml文件: <ui:UiBinder xmlns:ui="urn:ui:com.google.gwt.uibinder" xmlns:g="urn:import:com.google.gwt.user.client.ui"> <g:DialogBox ui:field="dialog"> <g:caption>My Dialog</g:caption> <g:HTMLPanel> <g:Button ui:field="closeButton" text="close" /> </g:HTMLPanel> </g:DialogBox> </ui:UiBinder> Java 文件: public class MyDialog { // here you do not inherit anything private static MyDialogUiBinder uiBinder = GWT.create(MyDialogUiBinder.class); interface MyDialogUiBinder extends UiBinder<Widget, MyDialog> { } @UiField DialogBox dialog; @UiField Button closeButton; public MyDialog() { // make cast to DialogBox dialog = (DialogBox) (uiBinder.createAndBindUi(this)); } public void hide() { dialog.hide(); } public void show() { dialog.center(); } @UiHandler("closeButton") public void onClick(ClickEvent event) { hide(); } } 最后我想出了一个办法,那就是把DialogBox放到一个看不见的HTMLPanel <g:HTMLPanel visible="false"> <g:DialogBox ui:field="wishlistDialogBox" autoHide="true"> <g:caption>Test</g:caption> <g:HTMLPanel> some widgets..</g:HTMLPanel> </g:DialogBox> </g:HTMLPanel> 然后像往常一样调用 show & hide DialogBox,即使 DialogBox 被包裹在一个看不见的 DialogBox 中,它也会显示 HTMLPanel。 getView().getWishlistDialogBox().show();


使用 StructureMap 连接不同的实现

我有一个非常简单的通用存储库: 公共接口IRepository 其中 TEntity : EntityObject 其中 TNotFound : TEntity, new() { 列表 我有一个非常简单的通用存储库: public interface IRepository<TEntity, TNotFound> where TEntity : EntityObject where TNotFound : TEntity, new() { IList<TEntity> GetAll(); TEntity With(int id); TEntity Persist(TEntity itemToPersist); void Delete(TEntity itemToDelete); } 我想为 Term 类型的存储库定义一个合约,没有任何特殊行为。所以它看起来像这样: public class TermNotFound : Term { public TermNotFound() : base(String.Empty, String.Empty) { } } public interface ITermRepository : IRepository<Term, TermNotFound> { } 现在为了测试,我想创建通用存储库的内存中实现,所以我有这个(为简洁起见,未完成): public class InMemoryRepository<TEntity, TNotFound> : IRepository<TEntity, TNotFound> where TEntity : EntityObject where TNotFound : TEntity, new() { private IList<TEntity> _repo = new List<TEntity>(); public IList<TEntity> GetAll() { return this._repo; } public TEntity With(int id) { return this._repo.SingleOrDefault(i => i.Id == id) ?? new TNotFound(); } public TEntity Persist(TEntity itemToPersist) { throw new NotImplementedException(); } public void Delete(TEntity itemToDelete) { throw new NotImplementedException(); } } 不难看出我希望它如何工作。对于我的测试,我希望注入通用 InMemoryRepository 实现来创建我的 ITermRepository。 好吧,我无法让 StructureMap 来做这件事。我尝试在扫描仪中使用 WithDefaultConventions 和 ConnectImplementationsToTypesClosing(typeof(IRepository<,>)) 但没有成功。接下来我可以尝试什么? 您的 InMemoryRepository 未实现 ITermRepository 接口。这就是为什么你无法连接它们。 你能用你所拥有的最好的办法就是注射 InMemoryRepository<Term, TermNotFound> 以获得 IRepository<Term, TermNotFound>。 如果你确实需要注入ITermRepository,那么你需要有另一个存储库类继承InMemoryRepository并实现ITermRepository: public class InMemoryTermRepository : InMemoryRepository<Term, TermNotFound>, ITermRepository { } 现在您可以使用以下方法将 ITermRepository 连接到 InMemoryTermRepository: .For<ITermRepository>().Use<InMemoryTermRepository>() 如果您有很多像 ITermRepository 这样的接口,您可以创建一个 StructureMap 约定,将 I...Repository 连接到 InMemory...Repository。默认约定是将 IClass 连接到 Class。


棱镜:ViewModelLocator.AutowireViewModel 不适用于内容视图

我正在将使用 Prism 的 Xamarin.Forms 应用程序迁移到 .NET Maui。该应用程序有一个 TabbedPage 导航。此迁移有效。 但是 ContentPages 包含几个 ContentView,如下所示: 我正在将使用 Prism 的 Xamarin.Forms 应用程序迁移到 .NET Maui。该应用程序有一个 TabbedPage 导航。此迁移有效。 但是 ContentPages 包含几个 ContentView,如下所示: <?xml version="1.0" encoding="utf-8" ?> <ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" xmlns:views="clr-namespace:MauiDemo.Views" x:Class="MauiDemo.Views.HomePage" Title="HomePage"> <VerticalStackLayout> <views:FirstContentView HeightRequest="200"/> <views:SecondContentView HeightRequest="200"/> </VerticalStackLayout> </ContentPage> 在 Xamarin 中,我能够将 prism:ViewModelLocator.Autowire="true" 属性添加到 contentview 中,并且 prism 找到了关联的视图模型。在 .NET maui 中,prism:ViewModelLocator.AutowireViewModel="Automatic" 属性没有任何作用。 例如,ContentView 的名称是 “FirstContentView”。关联的viewModel的名称是“FirstContentViewViewModel” 根据https://prismlibrary.com/docs/maui/migration.html中的描述,它应该可以工作,但事实并非如此。 配置这样的自动接线有什么技巧吗? 我使用 prism 存储库的当前克隆 https://github.com/PrismLibrary/Prism 以及带有最新 MAUI 组件的当前 .NET8 SDK 我使用区域而不是通过自动装配。具有不同 ContentView 的页面应该如下所示 <?xml version="1.0" encoding="utf-8" ?> <ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" xmlns:views="clr-namespace:MauiDemo.Views" xmlns:prism="http://prismlibrary.com" x:Class="MauiDemo.Views.HomePage" Title="HomePage"> <VerticalStackLayout> <ContentView prism:RegionManager.RegionName="FirstContent"/> <ContentView prism:RegionManager.RegionName="SecondContent"/> </VerticalStackLayout> </ContentPage> 所需的视图及其视图模型应在 MauiProgram 中注册为 RegisterForRegionNavigation container.RegisterForRegionNavigation<FirstContentView, FirstContentViewViewModel>(); container.RegisterForRegionNavigation<SecondContentView, SecondContentViewModel>(); .UsePrism(prism => { prism.RegisterTypes(container => { container.RegisterForNavigation<MainPage,MainPageViewModel>(); container.RegisterForNavigation<HomePage>(); container.RegisterForRegionNavigation<FirstContentView, FirstContentViewViewModel>(); container.RegisterForRegionNavigation<SecondContentView, SecondContentViewModel>(); }) .CreateWindow(navigationService => navigationService.CreateBuilder() .AddSegment<MainPage>() .NavigateAsync(HandleNavigationError)); }) 包含多个ContentView的页面的ViewModel应该为所需的ContentView调用RegionManager.RequestNavigate方法。 public class HomePageViewModel : ViewModelBase, IInitialize { private readonly IRegionManager _regionManager; public HomePageViewModel(IRegionManager regionManager) { _regionManager = regionManager; } public void Initialize(INavigationParameters parameters) { _regionManager.RequestNavigate("FirstContent", nameof(FirstContentView)); _regionManager.RequestNavigate("SecondContent", nameof(SecondContentView)); } } 仅此而已。它的工作原理如https://xamgirl.com/prism-regions-in-xamarin-forms/所述


我如何根据状态更改按钮颜色(绿色表示“接受”,红色表示“删除”)

如何根据状态更改按钮颜色(绿色表示“接受”,红色表示“删除”) 我是新人,为此使用 Laravel 框架。 这是我的观点 如何根据状态更改按钮颜色(绿色表示“接受”,红色表示“删除”) 我是新人,为此使用 Laravel 框架。 这是我的看法 <table class="table table-striped" id="example"> <thead> <tr> <th>ID no</th> <th>Form Name</th> <th style="text-align: center">Update</th> <th>Delete</th> <th>Status</th> </tr> </thead> @foreach($form as $show) {{--modal--}} <div class="modal fade mj_popupdesign mj_checkoutpopup" id="myModal2" tabindex="-1" role="dialog" aria-labelledby="myModalLabel"> <div class="modal-dialog" role="document"> <div class="modal-content"> <div class="modal-body"> <div class="col-lg-8 col-md-8 col-sm-12 col-xs-12 col-lg-offset-2 col-md-offset-2"> <div class="row"> <div class="mj_pricingtable mj_greentable mj_login_form_wrapper"> <form> <div class="mj_login_form"> <p>Are you sure you want to delete this post?</p> <br> <a href="" class="mj_btn btn btn-default pull-right glyphicon glyphicon-remove "> No</a> <a href="{{url('deleteForm',$show->id)}}" class=" pull-right mj_btn btn btn-danger glyphicon glyphicon-ok"> Yes</a> </div> </form> </div> </div> </div> </div> </div> </div> </div> {{--end modal--}} <tbody> <tr> <td> <p> {{$show->id}}</p> </td> <td> <h6><a href="{{url('JobDetails',$show->id)}}"style="color: rgb(0, 191, 243);font-size:18px;float: left;margin: 0;text-align: left">{{$show->jobTitle}}</a> </h6> <p> {{$show->created_at}} </p> </td> <td> <a href="{{url('UpdateFormView',$show->id)}}"> <span class="mj_btn btn btn-success">Update</span> </a> </td> <td> <span class="mj_btn btn btn-danger" data-toggle="modal" data-target="#myModal2">Delete</span> </td> <td><span class="mj_btn btn btn-warning">pending</span> </td> </tr> </tbody> @endforeach </table> </div> </div> </div> </div> 在我的控制器中public function AcquiredForm() { $acquired="Requirement Form"; $acquireForm=Job::where('jobType','LIKE','%'.$acquired.'%'); $form = $acquireForm->get(); return view('private-pages.company.aquire-form',compact('form')); } 数据库状态默认为待处理 数据库状态默认为pending 我在代码中没有看到 status 属性,但显示状态为待处理的纯字符串 <span class="mj_btn btn btn-warning">pending</span> <!-- while it suppose to be --> <span class="mj_btn btn btn-warning">{{ $show->status }}</span> 假设它确实存在,你可以做 <td> @if ($show->status === 'Accept') <span class="mj_btn btn btn-green">Accepted</span> @elseif ($show->status === 'Delete') <span class="mj_btn btn btn-danger">Deleted</span> @else <span class="mj_btn btn btn-warning">Pending</span> @endif </td> 参见:https://laravel.com/docs/5.1/blade#displaying-data <td> @if ($show->jobstatus === "Accepted") <span class="mj_btn btn btn-success">Accepted</span> @elseif ($show->jobstatus === "Rejected") <span class="mj_btn btn btn-danger">Rejected</span> @else <span class="mj_btn btn btn-warning">Pending</span> @endif </td> 或者当你使用 1. laravel esialy customaize this code nad add automatic refresh in the page to more interactive @php if($da->status == "requested") { echo "<td><button class='btn btn-primary'>Requested</button></td>"; } else { echo "<td><button class='btn btn-success'>Ordered</button></td>"; } @endphp


如何以 Svelte 方式设置导出和开槽零件的样式?

Svelte slot 的功能是否像 vanilla-js/dom 一样(我似乎无法让它工作)。 在 html/js 中我可以这样做: 身体{颜色:红色;} /* 从外部设置暴露部分的样式 */ ...</desc> <question vote="0"> <p>Svelte <pre><code>slot</code></pre>的功能是否像 vanilla-js/dom 一样(我似乎无法让它工作)。</p> <p>在 html/js 中我可以做:</p> <p></p><div data-babel="false" data-lang="js" data-hide="false" data-console="true"> <div> <pre><code>&lt;style&gt; body {color: red;} /* style exposed part from outside */ my-element::part(header) {color: green;} &lt;/style&gt; &lt;h1&gt;Hello World&lt;/h1&gt; &lt;my-element&gt; &lt;div slot=&#34;header&#34;&gt;&lt;strong&gt;Header&lt;/strong&gt;&lt;/div&gt; &lt;div slot=&#34;body&#34;&gt;Body&lt;/div&gt; &lt;/my-element&gt; &lt;script&gt; customElements.define(&#39;my-element&#39;, class extends HTMLElement { constructor() { super(); const shadowRoot = this.attachShadow({mode: &#39;open&#39;}); shadowRoot.innerHTML = ` &lt;style&gt; .container { border: solid 1px blue; padding: 5px; position: relative; &amp;:after { content: &#34;my-element&#34;; display: block; position: absolute; bottom: -.5em; right: 5px; border: inherit; background-color: white; padding: inherit; } } /* style inserted/slotted part from inside */ [part=&#34;body&#34;] ::slotted(div) { background-color: lightyellow; } &lt;/style&gt; &lt;div class=&#34;container&#34;&gt; &lt;header part=&#34;header&#34;&gt;&lt;slot name=&#34;header&#34;&gt;&lt;/slot&gt;&lt;/header&gt; &lt;hr&gt; &lt;div part=&#34;body&#34;&gt;&lt;slot name=&#34;body&#34;&gt;&lt;/slot&gt;&lt;/div&gt; &lt;/div&gt; `; } }); &lt;/script&gt;</code></pre> </div> </div> <p></p> <p>其中 <pre><code>h1</code></pre> 的全局样式为红色,标有 <pre><code>part=&#34;header&#34;</code></pre> 的元素从外部设置为绿色,插入 <pre><code>slot=&#34;body&#34;</code></pre> 的内容从内部(shadow dom)设置为绿色有浅黄色背景。</p> <p>我不知道如何在 svelte 中执行任何这种(受控)跨界样式? (例如,当使用 <pre><code>AppShell::part(content)</code></pre> 时,我收到错误:</p> <pre><code>[plugin:vite-plugin-svelte] C:/srv/svelte/yoda5/src/routes/+layout.svelte:23:18 Expected a valid CSS identifier C:/srv/svelte/yoda5/src/routes/+layout.svelte:23:18 21 | 22 | &lt;style&gt; 23 | AppShell::part(content) { | ^ </code></pre> </question> <answer tick="false" vote="0"> <p>这里有关于<a href="https://learn.svelte.dev/tutorial/slots" rel="nofollow noreferrer">老虎机的课程</a>。最好参考该工具的文档。 Svelte 的学习网站非常棒。</p> <pre><code>// Slotted component, say Test.svelte. &lt;div class=&#34;private-parent&#34;&gt; &lt;slot /&gt; &lt;/div&gt; &lt;style&gt; div.private-parent { color: blue; } &lt;/style&gt; </code></pre> <p>然后,您使用该组件:</p> <pre><code>&lt;script&gt; import Test from &#39;./Test.svelte&#39;; &lt;/script&gt; &lt;Test&gt; &lt;!-- This is the slot&#39;s content --&gt; &lt;p class=&#34;outside-style&#34;&gt;Hello!&lt;/p&gt; &lt;/Test&gt; &lt;style&gt; p.outside-style { color: darkred; } &lt;/style&gt; </code></pre> </answer> </body></html>


显示输入类型日期的占位符文本

占位符不适用于直接输入类型日期和日期时间本地。 占位符不适用于直接输入类型 date 和 datetime-local。 <input type="date" placeholder="Date" /> <input type="datetime-local" placeholder="Date" /> 该字段在桌面上显示 mm/dd/yyy,而在移动设备上则不显示任何内容。 如何显示 Date 占位符文本? 使用onfocus="(this.type='date')",例如: <input required="" type="text" class="form-control" placeholder="Date" onfocus="(this.type='date')"/> 使用onfocus和onblur...这是一个例子: <input type="text" placeholder="Birth Date" onfocus="(this.type='date')" onblur="if(this.value==''){this.type='text'}"> 在这里,我尝试了 data 元素中的 input 属性。并使用 CSS 应用所需的占位符 <input type="date" name="dob" data-placeholder="Date of birth" required aria-required="true" /> input[type="date"]::before { content: attr(data-placeholder); width: 100%; } /* hide our custom/fake placeholder text when in focus to show the default * 'mm/dd/yyyy' value and when valid to show the users' date of birth value. */ input[type="date"]:focus::before, input[type="date"]:valid::before { display: none } <input type="date" name="dob" data-placeholder="Date of birth" required aria-required="true" /> 希望这有帮助 <input type="text" placeholder="*To Date" onfocus="(this.type='date')" onblur="(this.type='text')" > 这段代码对我有用。只需使用这个即可 对于 Angular 2,你可以使用这个指令 import {Directive, ElementRef, HostListener} from '@angular/core'; @Directive({ selector: '[appDateClick]' }) export class DateClickDirective { @HostListener('focus') onMouseFocus() { this.el.nativeElement.type = 'date'; setTimeout(()=>{this.el.nativeElement.click()},2); } @HostListener('blur') onMouseBlur() { if(this.el.nativeElement.value == ""){ this.el.nativeElement.type = 'text'; } } constructor(private el:ElementRef) { } } 并像下面一样使用它。 <input appDateClick name="targetDate" placeholder="buton name" type="text"> 对于 React,你可以这样做。 const onDateFocus = (e) => (e.target.type = "datetime-local"); const onDateBlur = (e) => (e.target.type = "text"); . . . <input onFocus={onDateFocus} onBlur={onDateBlur} type="text" placeholder="Event Date" /> 我是这样做的: var dateInputs = document.querySelectorAll('input[type="date"]'); dateInputs.forEach(function(input) { input.addEventListener('change', function() { input.classList.add('no-placeholder') }); }); input[type="date"] { position: relative; } input[type="date"]:not(.has-value):before { position: absolute; left: 10px; top: 30%; color: gray; background: var(--primary-light); content: attr(placeholder); } .no-placeholder:before{ content:''!important; } <input type="date" name="my-date" id="my-date" placeholder="My Date"> 现代浏览器使用 Shadow DOM 来方便输入日期和日期时间。因此,除非浏览器出于某种原因选择回退到 text 输入,否则不会显示占位符文本。您可以使用以下逻辑来适应这两种情况: ::-webkit-calendar-picker-indicator { @apply hidden; /* hide native picker icon */ } input[type^='date']:not(:placeholder-shown) { @apply before:content-[attr(placeholder)]; @apply sm:after:content-[attr(placeholder)] sm:before:hidden; } input[type^='date']::after, input[type^='date']::before { @apply text-gray-500; } 我使用了 Tailwind CSS 语法,因为它很容易理解。让我们一点一点地分解它: ::-webkit-calendar-picker-indicator { @apply hidden; /* hide native picker icon */ } 使用其 Shadow DOM 伪元素选择器隐藏本机选择器图标(通常是日历)。 input[type^='date']:not(:placeholder-shown) { @apply before:content-[attr(placeholder)]; @apply sm:after:content-[attr(placeholder)] sm:before:hidden; } 选择所有未显示占位符的 date 和 datetime-local 输入,并且: 默认使用 placeholder 伪元素显示输入 ::before 文本 在小屏幕及以上屏幕上切换为使用 ::after 伪元素 input[type^='date']::after, input[type^='date']::before { @apply text-gray-500; } 设置 ::before 和 ::after 伪元素的样式。


SecurityException:不允许启动服务Intent { act=com.google.android.c2dm.intent.REGISTER pkg=com.google.android.gms (有额外功能)}

我尝试从 Google 获取我的 GCM 注册 ID。 我的代码: 字符串SENDER_ID =“722*****53”; /** * 向 GCM 服务器异步注册应用程序。 * * 存储注册信息... 我尝试从 Google 获取我的 GCM 注册 ID。 我的代码: String SENDER_ID = "722******53"; /** * Registers the application with GCM servers asynchronously. * <p> * Stores the registration ID and the app versionCode in the application's * shared preferences. */ private void registerInBackground() { new AsyncTask<Void, Void, String>() { @Override protected String doInBackground(Void... params) { String msg = ""; try { if (gcm == null) { gcm = GoogleCloudMessaging.getInstance(context); } regid = gcm.register(SENDER_ID); msg = "Device registered, registration ID=" + regid; // You should send the registration ID to your server over // HTTP, so it // can use GCM/HTTP or CCS to send messages to your app. sendRegistrationIdToBackend(); // For this demo: we don't need to send it because the // device will send // upstream messages to a server that echo back the message // using the // 'from' address in the message. // Persist the regID - no need to register again. storeRegistrationId(context, regid); } catch (IOException ex) { msg = "Error :" + ex.getMessage(); // If there is an error, don't just keep trying to register. // Require the user to click a button again, or perform // exponential back-off. } return msg; } @Override protected void onPostExecute(String msg) { mDisplay.append(msg + "\n"); } }.execute(null, null, null); } 我收到错误: 03-01 19:15:36.261: E/AndroidRuntime(3467): FATAL EXCEPTION: AsyncTask #1 03-01 19:15:36.261: E/AndroidRuntime(3467): java.lang.RuntimeException: An error occured while executing doInBackground() 03-01 19:15:36.261: E/AndroidRuntime(3467): at android.os.AsyncTask$3.done(AsyncTask.java:299) 03-01 19:15:36.261: E/AndroidRuntime(3467): at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:352) 03-01 19:15:36.261: E/AndroidRuntime(3467): at java.util.concurrent.FutureTask.setException(FutureTask.java:219) 03-01 19:15:36.261: E/AndroidRuntime(3467): at java.util.concurrent.FutureTask.run(FutureTask.java:239) 03-01 19:15:36.261: E/AndroidRuntime(3467): at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230) 03-01 19:15:36.261: E/AndroidRuntime(3467): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080) 03-01 19:15:36.261: E/AndroidRuntime(3467): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573) 03-01 19:15:36.261: E/AndroidRuntime(3467): at java.lang.Thread.run(Thread.java:841) 03-01 19:15:36.261: E/AndroidRuntime(3467): Caused by: java.lang.SecurityException: Not allowed to start service Intent { act=com.google.android.c2dm.intent.REGISTER pkg=com.google.android.gms (has extras) } without permission com.google.android.c2dm.permission.RECEIVE 03-01 19:15:36.261: E/AndroidRuntime(3467): at android.app.ContextImpl.startServiceAsUser(ContextImpl.java:1800) 03-01 19:15:36.261: E/AndroidRuntime(3467): at android.app.ContextImpl.startService(ContextImpl.java:1772) 03-01 19:15:36.261: E/AndroidRuntime(3467): at android.content.ContextWrapper.startService(ContextWrapper.java:480) 03-01 19:15:36.261: E/AndroidRuntime(3467): at com.google.android.gms.gcm.GoogleCloudMessaging.b(Unknown Source) 03-01 19:15:36.261: E/AndroidRuntime(3467): at com.google.android.gms.gcm.GoogleCloudMessaging.register(Unknown Source) 03-01 19:15:36.261: E/AndroidRuntime(3467): at com.example.gcm.DemoActivity$1.doInBackground(DemoActivity.java:177) 03-01 19:15:36.261: E/AndroidRuntime(3467): at com.example.gcm.DemoActivity$1.doInBackground(DemoActivity.java:1) 03-01 19:15:36.261: E/AndroidRuntime(3467): at android.os.AsyncTask$2.call(AsyncTask.java:287) 03-01 19:15:36.261: E/AndroidRuntime(3467): at java.util.concurrent.FutureTask.run(FutureTask.java:234) 03-01 19:15:36.261: E/AndroidRuntime(3467): ... 4 more 这是我的清单: <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.manyexampleapp" android:installLocation="preferExternal" android:versionCode="1" android:versionName="1.0" > <uses-sdk android:minSdkVersion="11" android:targetSdkVersion="18" /> <uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" /> <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> <uses-permission android:name="android.permission.GET_ACCOUNTS" /> <uses-permission android:name="android.permission.WAKE_LOCK" /> <uses-permission android:name="com.example.manyexampleapp.c2dm.permission.RECEIVE" /> <uses-permission android:name="com.example.manyexampleapp.gcm.permission.C2D_MESSAGE" /> <permission android:name="com.example.manyexampleapp.gcm.permission.C2D_MESSAGE" android:protectionLevel="signature" /> <application android:name="com.zoomer.ifs.BaseApplication" android:allowBackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme" > <meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" /> <activity android:name="com.zoomer.ifs.MainActivity" android:label="@string/app_name" android:configChanges="orientation|keyboardHidden|screenSize" android:launchMode="singleTop"> <!-- <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> --> </activity> <!-- PUSH --> <!-- WakefulBroadcastReceiver that will receive intents from GCM services and hand them to the custom IntentService. The com.google.android.c2dm.permission.SEND permission is necessary so only GCM services can send data messages for the app. --> <receiver android:name="com.example.gcm.GcmBroadcastReceiver" android:permission="com.google.android.c2dm.permission.SEND" > <intent-filter> <!-- Receives the actual messages. --> <action android:name="com.google.android.c2dm.intent.RECEIVE" /> <category android:name="com.example.manyexampleapp" /> </intent-filter> </receiver> <service android:name="com.example.gcm.GcmIntentService" /> <activity android:name="com.example.gcm.DemoActivity"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <!-- DB --> <activity android:name="com.example.db.DbActivity" android:label="@string/app_name" > <intent-filter> </intent-filter> </activity> <activity android:name="com.example.http.RestGetActivity" android:label="@string/app_name" android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen" > </activity> <activity android:name="com.example.fb.FacebookLoginActivity" android:label="@string/app_name" > <!-- <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> --> </activity> <activity android:name="com.example.http.SendFeedbackActivity" android:label="@string/app_name" > <!-- <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> --> </activity> <activity android:name="com.zoomer.general.SearchNearbyOffersActivity" android:label="@string/app_name" > <intent-filter> </intent-filter> </activity> <activity android:name="com.facebook.LoginActivity" android:label="@string/app_name" > <intent-filter> </intent-filter> </activity> <activity android:name="com.example.manyexampleapp.StoresListActivity" > <intent-filter> </intent-filter> </activity> <activity android:name="com.example.fb.ShareActivity" > <intent-filter> </intent-filter> </activity> <activity android:name="com.example.notifications.NotificationsActivity" > <intent-filter> </intent-filter> </activity> <activity android:name="com.example.fb2.no_use.MainActivity" > <intent-filter> </intent-filter> </activity> <activity android:name="com.zoomer.offers.OffersListActivity" > <!-- <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> --> </activity> <activity android:name="com.example.http.SearchNearbyOffersActivity" > <!-- <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> --> </activity> <service android:name="com.example.geo.LocationService" android:enabled="true" /> <receiver android:name="com.example.manyexampleapp.BootReceiver" > <intent-filter> <action android:name="android.intent.action.BOOT_COMPLETED" /> <action android:name="com.example.manyexampleapp.LocationService.LOCATION_BROAD_MSG" /> </intent-filter> </receiver> <meta-data android:name="com.facebook.sdk.ApplicationId" android:value="@string/app_id" /> </application> </manifest> 改变 <uses-permission android:name="com.example.manyexampleapp.c2dm.permission.RECEIVE" /> 到 <!-- This app has permission to register and receive data message. --> <uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" /> 您收到异常是因为您尚未定义所需的权限 如果应用程序开发后安装了播放服务, 可能会发生 com.google.android.c2dm.permission.RECEIVE 权限已被授予但 android 仍在抱怨同样的错误。 在这种情况下,您必须完全重新安装开发的应用程序才能使此权限发挥作用。 我认为你必须检查 Kotlin 版本兼容性。


© www.soinside.com 2019 - 2024. All rights reserved.