JsonStore - Load single record with a restful url? - extjs

All,
I have a JsonStore backing a form panel in my extjs app. I want to have the jsonStore load a single record based on an id value, but haven't found a good way to do that yet, and still keep the url restful.
My first attempt was to add a param to the jsonstore load() method with the id in it. That only adds the id as a request param, not attached to the url:
http://my-app/users/?id=123
instead of what i want:
http://my-app/users/123
Can someone help me out with this?

You can manually construct the URL that the store uses to query for data (via the implicit HttpProxy it creates for the URL). So your loading function would look like:
function store_refresh() {
json_store.proxy.conn.url = 'http://my-app/users/' + user_id;
json_store.reload();
}

Related

how to create dynamic url using get Route rather then id in Laravel 5.6

i want to create dynamic URL Route rather then id. I want to create url column in database i want use that column to create url in route.
Route::get('our-services/{service}', 'ServiceController#show');
it's my route code, using this route url look like this
127.0.0.1:8000/1
but i want to create like this,
127.0.0.1:8000/name
it's my link code that are create dynamically
Read More
it's dynamic url that create from database colum.
You use route model binding to customize the resolution logic. In the RouteServiceProvider boot method:
Route::bind('service', function ($value) {
return App\Service::where('url', $value)->first() ?? abort(404);
});

Angular state navigation - add querystring to URL

My application when starts can automatically navigate to a specified state like this:
localhost://start.html#/case
When a user navigates to this state some parameters are prepared internally to get specific data for templates shown in case state. I need to be able to have an URL with querystring added to the URL in order for the user to copy and paste it into his email or somewhere else. Something like this:
localhost://start.html?project=1234#/case
I have spent a considerable time trying to make it work. I tried
$location.search('project', '1234');
But could not get an URL that would actually work.
Please help me with this task.
Thanks
Hi you can add the parameters at the end of the url
localhost://start.html#/case?project=1234
then you can get the parameters in angular using $location
var projectId = $location.search().project;
// or
var projectId = $location.search('project');
// clear url
$location.search('project', null);

Fetch data from URL using Angularjs

How to fetch the data from URL and use it. I Have 2 pages where I am redirecting the data from one page to other.
Here is the code for first page:
{{child.name}}
on product.html how do I fetch the URL and the catid data.
If I use $location.path(); it is giving me an error
$location not defined
How do I fetch the information from URL?
If on product.html you are not using angular or any routing mechanism you could always get the current url using the following:
var url = window.location.href;
From here on, you will have to parse the corresponding query string parameters (in your case catid) in order to obtain the desired value. The following thread could give you some example on how to achieve that.

Backbone PUT request explicitly with out using id

I'm trying to PUT the data and my model doesn't have an id.
Is it possible to explicitly tell the Save() method to PUT the data irrespective of ID.
The save method has an options parameter that can override anything on the XHR:
model.save(newVals, { type: 'PUT' })
You can also override the isNew method. PUT vs POST is determined by the result of that method. You'll also want to make sure the URL is being created correctly for new and non-new objects.
Also consider setting the idAttribute correctly so that your model does have an id field that can be used to generate a correct url. Using POST and PUT correctly (POST new items, PUT updates to items) makes your api more intuitive.

Backbone try to update model in server after save

I use Rails 4 + backbone in my application.
Everything is good. New model is created in backbone and saved by calling:
newItem.save(null, {success: this.sendSuccess, error: this.sendError});
However, implementing a new feature I need to change one of the model attributes. What I see that a PUT action is fired just before sendSuccess is called, which I want to avoid.
Moreover, the url is very strange. Save action calls this url:
Remote Address:127.0.0.1:3000
Request URL:http://www.lvh.me:3000/api/user/1/tickets
Request Method:POST
and then, after server return the json with the modified attribute, backbone calls this url:
Remote Address:127.0.0.1:3000
Request URL:http://www.lvh.me:3000/api/user/1/tickets
Request Method:PUT
without the ticket id!
Is there any way to prevent backbone fire an update when server return the model with different attributes?
The problem was that I had a listener in my model exactly on the column that server changed:
initialize: function() {
this.on("change:status", this.statusChanged, this);
},
Now I had to figure out why the update url does not contain the model id.
I figured out that when I first created the model, from some reasons I couldn't assign it to the collection, so in order to save it I assign the url manually:
var newTicket = new MyApp.Ticket( ticketData );
newTicket.url = this.collection.url();
Now, the bug is that url is a function, and I simply overrided it!
I changed the code to:
newTicket.urlRoot = this.collection.url();
and now it works.
Backbone will always perform PUT if your model has an id attribute setted. Which makes sense when using RESTfull.
Be sure that you're really SAVING(new model withoud an ID) a data to server instead of UPDATING(model with an ID) to server.

Resources