Note that there are some explanatory texts on larger screens.

plurals
  1. POAccessing complex REST resources with Ext JS
    text
    copied!<p>I am accessing a REST service which exposes these two resources, a parent resource and a child resource: </p> <pre><code>/users /users/{userId}/account </code></pre> <p>So the resource "account" is not nested within the resource "user", it has to be accessed by a second request. There are examples for such REST APIs, e.g. <a href="https://stackoverflow.com/questions/7104578/rest-complex-composite-nested-resources">here</a></p> <p>I use these models to map users and their account to the Ext Js 4 data model:</p> <p><strong>User</strong></p> <pre><code>Ext.define("MyApp.model.User", { extend: "Ext.data.Model", fields: [ { name: "id", type: "string" }], associations: [{ model: "MyApp.model.Account", name: "account", type: "hasOne", reader: "json", getterName: "getAccount", setterName: "setAccount", foreignKey: "accountId" } ], proxy: { type: "rest", url: "/rest/users", reader: { type: "json", totalProperty: "total", root: "users" } } }); </code></pre> <p><strong>Account</strong></p> <pre><code>Ext.define("MyApp.model.Account", { extend: "Ext.data.Model", fields: [ { name: "id", type: "string" }], belongsTo: "MyApp.model.User", proxy: { type: "rest", reader: { type: "json"} } }); </code></pre> <p>The account proxy does not have a url (I hoped this would be created based on the parent user model). When I call user.getAccount() I get an exception because the proxy is missing the url. </p> <p><strong>Question</strong>: <em>Is there some way to setup the models such that Ext Js will access /users/{userId}/account WITHOUT updating the account proxy url manually with each parent userId?</em></p>
 

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