Note that there are some explanatory texts on larger screens.

plurals
  1. POExt JS: Load single database entry into model
    primarykey
    data
    text
    <p>I'm trying to create a model with a single database entry, instead of creating a store for just one row... doesn't make sense. Anyway, I can create the model by using the <a href="http://docs.sencha.com/extjs/4.2.1/#!/api/Ext.data.Model-static-method-load" rel="nofollow">static load method</a>, but the URL for my model's proxy is dynamic, so that's not an option, as I want to just load on the fly. Also, creating an instance of the model doesn't seem to work because I can't use the load method, due to it being static...</p> <p>I've started experimenting with an Ajax call to grab the data, and then loading it into an instance of the model, but the association relationships seem to not get created, even though the plain field values do. This is what I'm attempting to do:</p> <p><strong>Code</strong></p> <pre><code>// SectionsModel Ext.define('SectionsModel', { extend: 'Ext.data.Model', fields: ['name'] }); // MY_MODEL Ext.define('MY_MODEL', { extend: 'Ext.data.Model', fields: ['name', 'id'], hasMany: [{ associationKey: 'sections', name: 'getSections', model: 'SectionsModel' }], proxy: { type: 'memory', reader: { type: 'json', root: 'configuration' } } }); var url = 'my/url'; Ext.Ajax.request({ url: url, method: 'GET', scope: this, success: function(res) { var configObj = Ext.decode(res.responseText); var configModel = Ext.create('MY_MODEL', configObj); console.log(configModel); }, failure: function(res) { console.error('failed'); } }); </code></pre> <p><strong>Response</strong></p> <pre><code>{ "code": 200, "configuration": { "name": "TestConfiguration", "id": 1, "sections": [{ "name": "section1" }, { "name": "section2" }] } } </code></pre> <p>The above code is dummy code that I wrote for this example... think of it as pseudocode if it doesn't work. Like I said, it does work when I use the static <a href="http://docs.sencha.com/extjs/4.2.1/#!/api/Ext.data.Model-static-method-load" rel="nofollow">load method</a>, and I can successfully make the Ajax call... the issue is how to create a model with the given data. Would I need to pass in <strong>config</strong> to the model's constructor, and set the model's proxy's data to the passed in <strong>config</strong>? Is that proper protocol? I'm just trying to figure out the best approach here. Thanks!</p> <p>Cross-posted from the <a href="http://www.sencha.com/forum/showthread.php?279218-Load-single-database-entry-into-a-model.&amp;p=1020448" rel="nofollow">Sencha forums</a>.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload