-
started by klj613 • last reply by Alex Quirk • 4 years ago
Two years later, I find myself with this issue.
I have an event model with an array of attendees, on my page if the user hits a cancel or rsvp button it sends a request to the server that either adds or removes them from the list of attendees. Then i use the events findOne method to grab the newest version of that object, when a user rsvp'es all is good, when they cancel the correct data gets returned, I can see it in the network inspector, but the response data passed to my.done(function(response){})callback is the cached version -
asked by stephane.lemaitre • last reply by Justin Meyer • 4 years ago
Is this an older project? Anyway you could simplify the example? -
Here's where I'm at. I've set up a base model to inherit from with a static property called "serialization_keys" that is a list of attributes to include in serialization. Then I created my own serialization method:
- serialize: function() {
- var self = this;
- var serialized = {};
- var attribute_keys = this.constructor.keys(this);
- var serialization_white_list = this.constructor.serialization_keys || attribute_keys;
- $.each(attribute_keys, function(i, attr_key){
- if (serialization_white_list.indexOf(attr_key) === -1) return true;
- serialized[attr_key] = self.attr(attr_key);
- });
- return this._super.apply(new this.constructor(serialized), arguments);
- }
Basically if serialization_keys is not defined it serializes everything. if it is defined, it skips anything not in the list. It creates a new temporary model instance and serializes it with only the necessary keys.
This allows me to specify that the user should be skipped when serializing an activity.
Not ideal but it seems to do the trick. Anyone have a better solution?
-
asked by mnadig • 5 years ago
I see in https://github.com/jupiterjs/jquerymx/blob/master/model/list/list.js that _changed is set on a push and that get() checks changed to determine when to call _makdata. However, I don't see where _changed is ever set back to false. I imagine you'd want to set _changed back to false at the end of _makedata.I have a list that once populated is pretty static. I populate it by pushing the model instances and today found that it was calling _makedata repeatedly when I am calling get(). -
asked by spark85 • last reply by thecountofzero • 5 years ago
-
asked by R Prakash • last reply by Curtis Cummings • 5 years ago
I mean jQueryMX is only concerned with making the Ajax request. What happens once that request hits the server is up to the back end code. -
Override the attributes plugin and 'fix' it to perform proper inheritance. There is not going to be an official fix as the behavior is deemed by design, which I found out when filing issue #358 CanJS.
(In my honest opinion; having no way to 'untype' an attribute is a very weak reason to break the principle of least surprise in this way, but if that's the way the developers want to move forward; so be it. I'll just happily keep monkey-patching sane behavior back in..) -
started by kidphys • 5 years ago
When I call model.save(), the conversion will occur before the ajax call to server. Hence if the ajax call is failed, the conversion has already happened i.e. model's data is already changed.
And there is no way back. In my case, other controller is already bind to the model, hence they display model's data in server's format as well, which is undesired.How should we handle this case? What's the best practice? -
No, it makes no sense, because my question relates to custom implementation of the findOne.In fact,i missed ajax parameter 'json foo.models' that makes $.ajax to call Foo.models(response) to convert data to models.The method is documented here: http://javascriptmvc.com/docs.html#!jQuery.Model.static.modelIn custom non-AJAX/non-REST implementations this should be called manually.But it is not quite clean what is difference between new Model(data) and Model.model(data)The implementation is:
- model: function( attributes ) {
- if (!attributes ) {
- return null;
- }
- if ( attributes instanceof this ) {
- attributes = attributes.serialize();
- }
- return new this(
- // checks for properties in an object (like rails 2.0 gives);
- isObject(attributes[this._shortName]) || isObject(attributes.data) || isObject(attributes.attributes) || attributes);
- },
-
reported by Arjen_Haayman • 6 years ago
I am upgrading from 3.2 to 3.3 and now this is broken:- can.Model('Pand', {
- findall: function( params, success, error) {
- // when this is called 'success' is undefined
- }
- }, {
- // stuff
- }
When I call findAll
- Pand.findAll( { point: data.center,converted: true}, function( panden ) {// process});
in can/model/models.js line 589 this is called- var def = newMethod.apply(this, arguments);
(where arguments still are the object and the success function)
which then calls line 1071- var def = pipe( oldFind.call( this, params ), this, method );
the oldFind.call( this, params ) causes Pand.findAll to be called with only the 'params' filled. 'success' is undefined.
Am I doing something wrong here or is this a bug? -
asked by brecherbernd • last reply by brecherbernd • 6 years ago
I hope its not =), but it is. I'll correct that. -
asked by Joseph Tate • 6 years ago
What are people using to bust IE's broken caching? When IE makes an AJAX GET request, it returns from its own cache faking a 304 server return status. This is problematic if you have multiple writers or are trying to refresh server state after a PUT. What's the best way to work around this problem?I guess what I want to do is add a random query parameter on all AJAX GETs from IE so that it always passes it on to the server. Suggestions for least disruptive ways to do this? -
Everything seem to work as expected with donejs/canjs (an updated fiddle for canjs is here http://jsfiddle.net/2dL3C/4/).The code I quoted above is from jquerymx and the proposed fix for that version keeps all tests green. I don't know if a pull request is still relevant (everything is ok in the latest version) but I can send it to you if you want.Thanks again,Aggelos
-
Thanks Curtis. That's some awesome advice.
-
Hi Adept,I think you need to read the documentation againI'm defining the types of my class properties using attributes, it doesn't mean that the properties are declared static.You are just defining them as you would do in a strongly typed language such as C#.Kind regards- Thomas
-
started by ausnebu • 6 years ago
I am sending a Model to the server using Model.save(). It's all working, however I have a question about the payload. When I inspect the request being sent to the server, I see no 'JSON' message. Instead I just see form data, with each attribute on my Model in name/value pairs as per any standard FORM POST when submitting a HTML form. I guess I was expecting the JSON message to be bundled in a single field or something. Sorry if this is a newbie question, but can somebody please set me straight!Thanks. -
asked by ecvanbrussel • last reply by Curtis Cummings • 6 years ago
We've built tons of apps and rendering the HTML is never what causes performance issues. It's always the service layer (AJAX requests) or images (need to be sprites/optimized).You can try it out, but I'm certain that parsing an already rendered HTML document and hooking up the model instances will be orders of magnitude slower than using EJS. -
Can you create a jsfiddle and post the link here so we can see whats happening.
-
App.Models.Task.models returns a Model.List. You might have to overwrite it to get an actual App.Models.Task.List is that is differente from Model.List.
-
reported by isepman • 6 years ago
Hi everybody,I have a model which have an attribute called "updated". When I try to save an instance of this model, the attrbute "updated" is sent back by the remote server and overwrite the method "updated" called after each saves.Thus, My new instance can't call the method "updated" and throw the error self[method || type + "d"] is not a function.This problem can easily be reproduce in the cookbook tutorial by just adding a created field in the form init.ejs:- <h2>New recipe</h2>
- <p>
- <label for='name'>Name</label> <br/>
- <input type='input' name='name' id='name'/>
- </p>
- <p>
- <label for='created'>Created</label> <br/>
- <input type='input' name='created' id='created'/>
- </p>
- <p><label for='description'>Description</label><br/>
- <textarea name='description' id='description'/></textarea>
- </p>
- <p><input type='submit' value='Create'/></p>
I could just change the name of this property, but I'm querying google agenda api and I can't change the created and updated attributes of the responseIs there a way to get around this?thanks -
You may watch the length of list.
-
started by justbla • last reply by markalanevans • 6 years ago
I have a model global model called Np.Models.StoreAdminState its referenced as global variable "State".Model code here: http://pastie.org/4832921I Just upgraded JMVC 3.2.3 after reading this post and your comment:.... not currently but coming in 3.2.3I am still experiencing the same issue. Model observation on attribute changes doesn't seem to be working with this selectedProducts data change.State.bind('selectedProducts', function(ev){- console.log('data changed');
- });
selectedProducts is just one of the attributes, In my app selectedProducts gets changed as i select items in my view, yet I never see the event trigger.Did model/observe get rolled into 3.2.3?What am i doing wrong?Also with the addition of 3.2.3, does that mean in my controller i should be able to do- "{Np.Models.StoreAdminState} selectedProducts": function(el, ev){
- console.log("updated");
- },
What i mean by that is does that mean i can bind to attribute changes in the controller? -
My model also without trigger ajax request,I create an instance like: GLOBAL.models.userdata = new Ra.Models.Userdata({userData:data}); I want to delete this instance,so I use GLOBAL.models.userdata.destroy(),but an error occured showing that there is no method.I don't know how can I destroy this instance?
-
Thanks for your reply. It did not reflect what I was seeing, but after probing deeper into the documentation, I think you might be alluding to $.Model.model, right? That is, if you specify a data type of "json someModel.model", then an Ajax converter converts the response into an instance of the model class, right?I was not using a dataType that included a model and thus, I was getting simply the JSON back.Is this what you had meant?
-
Ahh right. I though it created model objects, instances which hold data. Thanks Curtis. understood!
- « Newer
- Older »
Sub forum actions