Currently, I am working on developing a custom Wordpress theme using technologies like Javascript, Requirejs, and Backbonejs. As part of this process, in the index route, I have set up a new postsCollection
app.postsCollection = new Posts.Collection();
to store all WordPress posts. Subsequently, I call .fetch() app.postsCollection.fetch( { success: ..., error: ... } );
Below is the code snippet from my modules/posts/collection.js file :
define( function( require, exports, module ) {
"use strict";
var app = require( 'app' );
var PostModel = require( './model' );
var PostsCollection = Backbone.Collection.extend( {
model : PostModel,
url : app.jsonApi + "get_posts/",
parse: function( response ) {
return response.posts;
}
} );
module.exports = PostsCollection;
} );
Issue at hand:
My current challenge involves extending the PostModel by defining
var ImagePostModel = PostModel.extend( { ... } );
and var GalleryPostModel = PostModel.extend( { ... } );
. The objective is to use the specific model based on the post type (either image or gallery) during data collection. How can I achieve this effectively?