在视图表单字段中清除绑定

时间:2016-02-02 02:25:34

标签: knockout.js

用户发帖后,我似乎无法弄清楚如何清除表单中的值。敲除绑定是否有任何类型的重置?我在帖子的$post_id = 298; $image_ids = array (); // get all the galleries in the post if ( $galleries = get_post_galleries( $post_id, false ) ) { foreach ( $galleries as $gallery ) { // pull the ids from each gallery if ( ! empty ( $gallery[ 'ids' ] ) ) { // merge into our final list $image_ids = array_merge( $image_ids, explode( ',', $gallery[ 'ids' ] ) ); } } } // make the values unique $image_ids = array_unique( $image_ids ); // convert the ids to urls -- $gallery[ 'src' ] already holds this info $image_urls = array_map( "wp_get_attachment_url", $image_ids ); // ---------------------------- // echo '<pre>'; print_r ( $image_ids ); print_r ( $image_urls ); echo '</pre>'; 中尝试了 @Test def test(): Unit = { // GIVEN when( serviceMock. call("one") ). thenReturn("123") // WHEN val result = serviceMock.call("one") // THEN verify( serviceMock, times(1) ). call( eqTo("one") ) assert(result == "123") } ,但这些字段并未从表单字段(视图方面)中清除。

self.user = null

1 个答案:

答案 0 :(得分:1)

将user设置为null将不起作用,因为用户不是可观察的。 DOM通过可观察的更改进行更新。更新您的代码如下,它应该适合您:

self.user = ko.observable(userModel);
...
// inside done callback
self.user(null);