【问题标题】:Passing an object with Aurelia router.navigate to a view使用 Aurelia router.navigate 传递对象到视图
【发布时间】:2016-11-03 08:24:53
【问题描述】:

当我点击一行时,我需要做一个主从视图。我有code in a branchhere's the commit link

  let urlDetail = this.router.generate('energy-details', {model: this.model});
  this.router.navigate(urlDetail);

这可行,但查询字符串很糟糕。如何将模型发送到内存中?

这真的很难找到一个例子。 https://github.com/softchris/aurelia 是最好的。 有没有更好的方法来做主从视图?我是 Aurelia 的新手。

http://localhost:5000/#/energy-details?model%5BdataSeriesId%5D=ES&model%5BcountryId%5D=392&model%5BcountryName%5D=Japan&model%5BtransactionCode%5D=01&model%5BcommodityTransactionId%5D=ES01&model%5BcommodityTransactionName%5D=Electricity%20-%20solar%20production%2C%20public&model%5Byear%5D=2000&model%5Bunit%5D=Kilowatt-hours%2C%20million&model%5Bquantity%5D=2&model%5BfootnoteSequenceId%5D=0.

【问题讨论】:

    标签: aurelia


    【解决方案1】:

    如果您不想使用 id,请重新考虑。通常情况下,您需要进行新查询才能获得更多数据。

    如果您的用例不可能,那么拥有一个 DataManager 单例可能是有意义的。

    • 创建一个 DataManager 类,将其注入到 List 和 Detail ViewModel 中。默认情况下,每个注入的类都是 aurelia 中的单例
    • 在 ViewModel 列表中,确保您的数据保存在 DataManager 中
    • 仅通过 id 进行路由
    • 在 ViewModel 的详细信息中调用 DataManger 的方法 getModelById(id)

    【讨论】:

    • 感谢“如果您不想使用 id,请重新考虑。”。我在想一些东西是内置的,但 Singleton 是另一个好主意。
    • 啊哈哈抱歉。是的,我也经常想在加载完整数据之前传递数据以快速预览详细信息。但是将数据存储到路由中会使处理页面历史的序列化变得繁重。
    猜你喜欢
    • 2013-04-10
    • 2019-01-08
    • 2018-01-01
    • 2012-03-08
    • 1970-01-01
    • 2017-04-26
    • 2016-09-28
    • 1970-01-01
    相关资源
    最近更新 更多