用原型扩展敲除视图模型 [英] Extending knockout viewmodels with prototype

查看:84
本文介绍了用原型扩展敲除视图模型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果已经定义了视图模型,则可以通过手动或自动使用映射插件进行定义,是否有问题通过使用原型在代码的后面扩展"(添加属性/功能)视图模型?

If a viewmodel is already defined, either manually or automatically with mapping plugin, is there any problem to "extend" (add properties/functions) the viewmodel later in the code by using prototype?

我知道映射插件的create回调,我只想知道使用原型是否有任何影响?我问的原因是因为我从服务器端代码生成了大部分的视图模型,但是有时需要比最初生成时更晚地扩展视图模型.

I'm aware of the create callback of mapping plugin, I just want to know if there are any implications of using prototype instead? The reason I'm asking is because I'm generating large parts of the viewmodels from server side code, but sometimes need to extend the viewmodel later than at initial generation.

推荐答案

我认为这没有任何问题,我使用通过对应结构化JSON的映射插件实例化的大型深度视图模型图,我使用了原型来定义具有有用属性的"AbstractViewModel"和toJSON替代"等.

I don't think there is any problem with this, I work with a large deep view model graph instantiated via the mapping plugin from correspondingly structured JSON and I use prototypes to define an "AbstractViewModel" with useful properties and toJSON "overrides" among other things.

这篇关于用原型扩展敲除视图模型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆