Parse/オブジェクトを削除する
キーワード
- Parse
- JavaScript
- Object
- destroy
概要
アプリケーションに定義したクラスのオブジェクトを削除します。
今回のサンプルは次のクラスを定義したものとしています(※Parse規定のカラムを除く)。
- Post
| CENTER:BGCOLOR(#EEEEEE):カラム | CENTER:BGCOLOR(#EEEEEE):型 |
| title | String |
| body | String |
サンプル
// オブジェクトを削除する
var destroy = function(id) {
// クラス
var Post = Parse.Object.extend('Post');
// インスタンス
var post = new Post();
// 属性
post.set('id', id);
// 削除
post.destroy({
success: function(post) {
jQuery('#message').text('ポスト削除: ' + post.id);
},
error: function(post, error) {
jQuery('#message').text('ERROR: ' + error.description);
}
});
};
// イベント処理(Parseとは直接関係ないところ)
jQuery('input[name=object-destroy-post]').click(function() {
var id = jQuery('input[name=object-destroy-id]').val();
if (id.length > 0) {
destroy(id);
} else {
jQuery('#message').text('WARN: ' + 'idを入力してからdeleteしてね。');
}
});
解説
あとで。
参考
作成日 2013-08-17
