Computed properties in Backbone

后端 未结 4 1176
暖寄归人
暖寄归人 2020-12-03 05:25

I have a scenario where the data being manipulated on the client is presented and interacted with in a different way than it is represented on the server.

Consider t

4条回答
  •  时光取名叫无心
    2020-12-03 05:53

    You have some options:

    • Override toJSON to return the computed duration

    • Create a duration() method on the Backbone Model. Only downside that you have to call it differently (obj.duration() instead of obj.get('duration')). In your view that hands obj.toJSON() to your template, mix in the duration attribute

    • Use https://github.com/asciidisco/Backbone.Mutators (or similar) to create a derived getter for duration

提交回复
热议问题