I receive Jsonp like:
Mycallback([['name1', 'id1', 'price1'], ['name2', 'id2', 'price2']]
and want to use it for loading store (throuh Jsonp request all works correctly, but I need to use store.load())
How can I load arrays in my store?
How can I access data in callback function?
create a model with fields name, id, price and set the store's model property as this model that you have defined then sencha internally stores the data as an array
Related
I have an AngularJS model like this:
$scope.model = {name: "Joe", isMale: true};
In the view I bind the model.isMale to a checkbox.
Now I ask a backend for an update ($http.get()). In the onSuccess callback I simply assign the response value to $scope.model. If the backend does not send me the whole model, e.g. does not send the isMale flag, the $scope.model does not have the flag isMale any more. When I later on change the name for example in the UI and send these data to the backend, the flag isMale is not sent to the backend anymore, since the model does not contain it. Is there a way to check if the view elements' model-bindings do exist? Is there a better solution than just overwriting the model with the value I get from the backend?
Thanks
You can extend your model and overwrite your default model value with the one from api response. That way your default will be overridden only if that is present in api response:
angular.extend($scope.model, response)
for shallow copy, or
angular.merge($scope.model, response)
for deep(recursive) copy
This should work in your scenario
And do refer for the intricate details of difference between angular.copy(), 'angular.extend()' and angular.merge() here: http://davidcai.github.io/blog/posts/copy-vs-extend-vs-merge/
Is always equivalent use one or the other?
These prints in console same things
class Model extends Backbone.Model
defaults:
some: 'thing'
other: 'item'
model = new Model
console.log model.attributes
console.log model.toJSON()
toJSON() is a standard method that the JavaScript JSON serializer looks for when serializing an object.
In the context of Backbone, if you override toJSON in your model you can change the format of values which get sent to the server when saving. For example you could filter out read only fields like time stamps.
attributes is the JavaScript object containing the model data, that's what gets altered when you use model.set(). Except if you don't use set() to alter values, then you bypass all the events and loose some of the benefits of backbone. So only use attributes directly if you know what you're doing.
Backbone.js sents an POST on updated objects instead of an PUT.
I think this is because mongoDB uses _id instead of id.
How do I say backbone.js to use _id instead of id?
I already tried some server-side change but I think it would be easier just to say that backbone should use another attribute as id.
MongoDB: output 'id' instead of '_id'
From the fine manual http://backbonejs.org/#Model-idAttribute
idAttribute model.idAttribute
A model's unique identifier is stored under the id attribute. If you're directly communicating with a
backend (CouchDB, MongoDB) that uses a different unique key, you may
set a Model's idAttribute to transparently map from that key to id.
Id attribute can be changed per model like
var Meal = Backbone.Model.extend({
idAttribute: "_id"
});
To make it default for all models (eg., if we are using mongodb), override the default setting by placing this LOC in your app js file that runs after backbone.js
//override the id attribute for model
Backbone.Model.prototype.idAttribute = '_id';
I have an Ext.form.Panel that calls a PHP page by passing search parameters. The PHP page executes a query based on those params and returns a JSON structure. In the form-success handler I would like to get the JSON, build a store and fill a grid.
How can I do it using ajax? If I use Ext.form.panel submit() it always invoke onFailure because it does not find [{success:val,message:msg}]. Which is the correct way to build a form that gets back a JSON string?
Why don't you just have your search panel call a load() action on grid's JsonStore? A lot easier than manually flling the store from JSON string.
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();
}