首页 \ 问答 \ 如何在Svelte中有条件地禁用字段?(How to disable field conditionally in Svelte?)

如何在Svelte中有条件地禁用字段?(How to disable field conditionally in Svelte?)

在Angular 2+中(例如),我可以使用这种语法来有条件地禁用一个字段:

<input [disable]="booleanCondition" type="text">

在Svelte中,我试图按照如下方式执行操作,但它不起作用:

<input {booleanCondition ? 'disabled=""' : ''} type="text">

我该怎么做?


In Angular 2+ (for example), I can use this syntax to disable a field conditionally:

<input [disable]="booleanCondition" type="text">

In Svelte I'm trying to do as follows, but it doesn't work:

<input {booleanCondition ? 'disabled=""' : ''} type="text">

How can I do it?


原文:https://stackoverflow.com/questions/50352748
更新时间:2023-08-19 20:08

最满意答案

通常,在软件工程中,存储库用于从应用程序的其余部分(通常直接是业务层)抽象数据层(数据库,Web服务),一个很好的例子就是预订网站的这种模式:

存储库样式

它通过发布/订阅异步连接接收更新,并将它们发送到其他组件。 因此组件彼此独立。
因此,Repository只是一个简单的中介类,用于使应用程序更加模块化,以便您可以更轻松地交换部分,并确保应用程序的其余部分不会打扰数据库连接或HTTP调用等等。 从技术上讲,您可以从Application(或其他任何东西)继承并使用它来保存静态变量等等。

正如这里所解释的:

应用程序对象不能保证永远留在内存中,它会被杀死。 与流行的看法相反,该应用程序将不会从头开始重新启动。 Android将创建一个新的Application对象并启动用户之前的活动,以便首先假定应用程序从未被杀死。

所以这完全取决于你,你可以根据自己的意愿使用存储库样式,它根本不与Room或其他任何东西联系在一起。


In general, in Software Engineering a Repository is used to abstract the Data Layer (Database, Web Service) from the rest of the application (usually directly Business Tier), a good example would be this schema of a booking website:

Repository style

It receives the updates via the Publish/Subscribe asynchronous connection and sends them to the other components. So the components are independent of each other.
So Repository is just a simple mediator class that is used to make the application more modular, so that you can swap out pieces easier, and make sure that the rest of the app doesn't bother with DB connections or HTTP calls and so on. So technically, you can inherit from Application (or anything else) and use it to save static variables and so on.

But as explained here:

The application object is not guaranteed to stay in memory forever, it will get killed. Contrary to popular belief, the app won’t be restarted from scratch. Android will create a new Application object and start the activity where the user was before to give the illusion that the application was never killed in the first place.

So it's entirely up to you, you can use the repository style as you wish, it's not at all tied to Room or anything else.

相关问答

更多
  • 更新: AmbientMode似乎是处理此问题的新方法。 正如@codingjeremy在他的帖子中提到的,他们现在已经在Android支持库27.0.0中引入了它。 原版的: 我通过将WearableActivity中的实现逐字复制到我自己的项目中定义的新WearableFragmentActivity类,然后将其更改为扩展FragmentActivity来解决这个问题。 直接获得Google的支持将是理想的解决方案,但如果您在此期间寻找解决方法,这应该可行。 Update: AmbientMode se ...
  • 在您的情况下,将LiveData替换为LiveData>就足以解决您的问题。 但是,我建议尝试在官方示例中提供的RealmLiveResults类: /** * This class represents a RealmResults wrapped inside a LiveData. * * Realm will always keep the RealmResults up-to-date whenever a change occurs on a ...
  • 我并不完全处于相同的情况,但下面是我如何处理使用switchMap和RxJava关系获取数据。 也许它可以帮到你。 public LiveData> fetchAllItems() { LiveData> itemLiveData = mItemDao.fetchAllItems(); itemLiveData = Transformations.switchMap(itemLiveData, input -> { MutableL ...
  • 所以,我最终这样做了: 该片段过滤ViewModel的状态。 副作用:过滤器状态可以被多个(即,随后由于配置改变)片段实例使用。 也许你想要,也许不是。 我做。 ViewModel包含一个MediatorLiveData实例。 它有一个来源:Room DB LiveData对象。 源代码简单地改变为中介。 如果过滤器被片段更改,则源将被重新调换。 回答我的详细问题: 没有后过滤 是的,需要更换过滤器 我不重用ComputableLiveData(不确定这是否可能) 关于评论中的讨论: 我不应用分页 关于房间 ...
  • 你的函数getUnloadedOffers()是否返回空的mutableList? 我不确定是否将items传递给itemsLiveData会起作用,因为观察LiveData正在bg线程上运行(如果我没有弄错) Does your function getUnloadedOffers() return empty mutableList? I'm not sure if passing items to itemsLiveData is going to work, since observing Live ...
  • 通常,在软件工程中,存储库用于从应用程序的其余部分(通常直接是业务层)抽象数据层(数据库,Web服务),一个很好的例子就是预订网站的这种模式: 它通过发布/订阅异步连接接收更新,并将它们发送到其他组件。 因此组件彼此独立。 因此,Repository只是一个简单的中介类,用于使应用程序更加模块化,以便您可以更轻松地交换部分,并确保应用程序的其余部分不会打扰数据库连接或HTTP调用等等。 从技术上讲,您可以从Application(或其他任何东西)继承并使用它来保存静态变量等等。 但正如这里所解释的: 应用程 ...
  • 问题出在AppCompatActivity ,它将ViewModel与LiveData一起LiveData 。 LiveData观察器仅针对Fragment调用,而不是针对Activity调用。 我使用了实现LifecycleOwner接口的AppCompatActivity ,但正确的是实现LifecycleRegistryOwner 。 致谢: https : //issuetracker.google.com/issues/63764057 The problem was inside AppComp ...
  • 当您希望在不同Threads之间轻松进行通信时,您需要处于同一个进程中。 在AndroidManifest.xml您可以在活动 , 服务 (与SyncAdapters相关), 内容提供商和广播接收器上指定一个名为android:process=":processName"的属性,它可以帮助您超越堆的默认限制(内存)对于单一过程。 这些是总结的PRO / CONS: 多进程PRO:你有更多的内存来运行你的应用程序,如果进程崩溃,它不会崩溃其他的。 多进程CONS:让进程相互通信要困难得多(但并非不可能)但显然 ...
  • 在Android Room代码中潜水后,我发现了一些东西: Room annotation处理器使用javapoet库从Room annotations( @Query , @Query ...)生成代码 根据查询的结果类型( QueryMethodProcessor ),它使用“binder”或另一个。 在LiveData的情况下,它使用LiveDataQueryResultBinder 。 LiveDataQueryResultBinder生成一个LiveData类,其中包含一个Invalidation ...
  • 请考虑Google的架构组件教程中的以下代码: 这不是教程。 它是一些代码片段的参考,其中许多代码片段无法编译,因为它们用于说明语法和调用结构,而不是实际运行。 请注意LiveData对象在声明期间被实例化。 这就是编写代码片段的人选择做的事情。 所以谷歌的建议是在声明期间实例化它们。 谷歌没有提出这样的建议。 您引用的代码片段就是一个例子 ,仅此而已。 为什么在声明期间应该实例化LiveData对象? 他们不具有初始值设定项的字段。 如果您愿意,欢迎您在构造函数中实例化它们。 ViewModel具有关于构 ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)