简体   繁体   English

如何删除ractivejs对象

[英]How do you delete a ractivejs object

I know in vanilla JS you can just use the delete command to remove an object but I can't find anything in the docs for object manipulation. 我知道在香草JS中,您只能使用delete命令删除对象,但是我在文档中找不到用于对象操作的任何内容。

For example how would I delete this object in ractivejs? 例如,如何在ractivejs中删除该对象?

template.set('object', {hello: 'world', bye: 'world'});

I want to later on delete the bye object from that 'object'. 我想稍后bye从该“对象”中删除bye对象。

From the template's perspective, it usually doesn't matter if you just set the value to undefined : 从模板的角度来看,通常只要将值设置为undefined

template.set( 'object.bye' );

Unless you're using it in a hash, then you can delete the key and call update: 除非您在哈希中使用它,否则您可以删除密钥并调用更新:

delete template.get( 'object').bye;
template.update( 'object.bye' );

It's currently a requested feature ( https://github.com/ractivejs/ractive/issues/1649 ) to add an unset method: 当前是一种请求功能( https://github.com/ractivejs/ractive/issues/1649 ),用于添加未unset方法:

template.unset( 'object.bye' );

If you look in the comments on that issue, there's a Ractive.prototype.unset polyfill you can use. 如果您查看有关该问题的评论,则可以使用Ractive.prototype.unset

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM