Nuttertoo1s
V2EX  ›  问与答

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

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