Nuttertoo1s
V2EX  ›  问与答

计数器里的数字怎么用 ViewModel 保存

  •  
  •   Nuttertoo1s · Dec 22, 2020 · 1556 views
    This topic created in 1970 days ago, the information mentioned may be changed or developed.
    因为是类似购物车的功能,所以 Item 数量是不固定的,如果我想在 ViewModel 里面使用 LiveData 进行数据更新要怎么操作
    3 replies    2020-12-23 11:18:10 +08:00
    Nuttertoo1s
        1
    Nuttertoo1s  
    OP
       Dec 22, 2020
    有点眉目了,好像不能使用 MutableLiveData,要使用 LiveData 进行更细致的字段更新
    q197
        2
    q197  
       Dec 23, 2020
    这个我记得官方文档示例里就有
    Nuttertoo1s
        3
    Nuttertoo1s  
    OP
       Dec 23, 2020
    @q197 是有,但是我现在的情况是 Item 数量不固定,会动态变化的,如果使用 MutableLiveData 要预先设置好变量
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   5114 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 43ms · UTC 09:44 · PVG 17:44 · LAX 02:44 · JFK 05:44
    ♥ Do have faith in what you're doing.