小编Squ*_*eOJ的帖子

更新后 Blazor 列表刷新

这篇文章已完全更新,将所有代码放在一个类中,并尽量使其简单明了。

该项目完美运行,除了一件事: 更新学生记录时,更新数据库,但不更新可见列表

我能够看到更改的唯一方法是刷新整个页面(请参阅代码底部的 NavigationManager 行)。

你能帮我理解我在这里没有做什么吗?

@page "/Students2";
@using ParentChild.Models;
@inject IJSRuntime JS;                          // Used for Confirmation Dialog & Alert Box
@inject NavigationManager NavigationManager     // Used to Refresh Entire Page

<h3>Students 2</h3>

@if (byStudents == null)
{
    <p><em>Loading...</em></p>
}
else if (!byStudents.Any())
{
    <p><em>No students in database.  Please add some.</em></p>
}
else
{
    <table class="table">
        <thead>
            <tr>
                <th>First</th>
                <th>Last</th>
                <th>Street</th>
                <th>City</th>
                <th>State</th>
                <th>Zip</th>
                <th>Cell</th>
                <th>Home</th>
                <th>Email</th>
                <th>Note</th>
                <th></th>
            </tr>
        </thead>
        <tbody>
            @foreach (var byStudent in byStudents)
            {
                <tr> …
Run Code Online (Sandbox Code Playgroud)

c# blazor

5
推荐指数
1
解决办法
893
查看次数

使用 Kotlin Jetpack Compose 在 Composable 函数中显示资源文本文件

我正在尝试使用 Kotlin 从我的 Assets 文件夹中读取文本文件并将其显示到 Compose 文本小部件。Android Studio 北极狐 2020.3

以下代码成功运行并将文本文件显示到输出控制台,但是我无法弄清楚如何获取文本文件并将其传递到 Compose 文本小部件。

您会注意到我在 ReadDataFile() 内有 2 个 text() 调用。第一个 text() 位于 try{} 之外,并且工作正常,但是try{} 内的 text() 会导致错误:“可组合函数调用不支持 Try catch”

我怎样才能做到这一点?

谢谢!

package com.learning.kotlinreadfile

import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.material.MaterialTheme
import androidx.compose.material.Surface
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.platform.LocalContext
import com.learning.kotlinreadfile.ui.theme.KotlinReadFileTheme
import java.io.InputStream
import java.io.IOException

class MainActivity : ComponentActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContent {
            KotlinReadFileTheme {
                // A surface container using the 'background' …
Run Code Online (Sandbox Code Playgroud)

kotlin android-jetpack-compose

4
推荐指数
1
解决办法
3967
查看次数

如何重构简单的 LazyColumn 列表示例

我是 Jetpack Compose 的新手,我正在尝试弄清楚当用户单击 FloatingActionButton 时如何重新组合 LazyColumn 列表。

如图所示,我有一个基本的脚手架布局,其中包含一个用于内容的 LazyColumn。底部是一个 FloatingActionButton。我希望能够单击该 FloatingActionButton,将“Molly”添加到我的姓名列表中,让应用程序重新组合我的列表,并显示包括 Molly 在内的完整列表。代码如下图。

在此输入图像描述


这是我的代码:

package com.learning.lazylistexample

import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items
import androidx.compose.material.*
import androidx.compose.runtime.Composable
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import com.learning.lazylistexample.ui.theme.LazyListExampleTheme
import kotlinx.coroutines.launch

data class ListItem(val name: String)

private var listItems: MutableList<ListItem> = mutableListOf(
    ListItem("Al"),
    ListItem("Barb"),
    ListItem("Cheryl"),
    ListItem("Dave"),
    ListItem("Ed"),
    ListItem("Frank"),
    ListItem("Gloria"),
    ListItem("Henry"),
    ListItem("Ingrid"),
    ListItem("Jack"),
    ListItem("Kayla"),
    ListItem("Larry")
)

class MainActivity : ComponentActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContent { …
Run Code Online (Sandbox Code Playgroud)

android-jetpack-compose lazycolumn

3
推荐指数
1
解决办法
2777
查看次数

标签 统计

android-jetpack-compose ×2

blazor ×1

c# ×1

kotlin ×1

lazycolumn ×1