Extjs 4.1, Making JSON array for Store sync - extjs4.1

When I sync for edited grid, extjs pass JSON data to Server by AJAX.
If I edit multiple row, and sync then it make JSON array. But if I edit just single row,
it will pass just a JSON data.
So I have some problem with receiving the parameter because the parameter type is vary.
My question is,
Is it possible to make JSON array date even for single edited grid?
If so, how should I do? anybody know please please advice me.
[Single]
[Multiple]
And this is part of grid store,
proxy: {
type: "ajax",
api: {
update: 'Order/ItemUpdate',
read: 'Order/ItemList',
create: undefined,
destroy: undefined
}
}

Just set the allowSingle config of Ext.data.writer.Json to false. As covered here in the docs.
I am pretty sure that this can be done from your proxy config, e.g.:
proxy: {
type: 'ajax',
writer: {
type: 'json',
allowSingle: false
},
api: {
update: 'Order/ItemUpdate',
read: 'Order/ItemList',
create: undefined,
destroy: undefined
}
}

Related

What are the available options for LayoutAnimation.Types

I have a custom layout animation taken from here.
var CustomLayoutAnimation = {
duration: 200,
create: {
type: LayoutAnimation.Types.linear,
property: LayoutAnimation.Properties.opacity,
},
update: {
type: LayoutAnimation.Types.curveEaseInEaseOut,
},
};
When running the code i get the following warning
Warning: Failed config type: The config config.update.type is marked
as required in LayoutAnimation.configureNext, but its value is
undefined.
The code has an entry for update.type, yet the warning says it's undefined. I'm guessing that the permitted values have been updated since the gist was written.
I tried to find out the list of available permitted entries but they are not listed in the React Native LayoutAnimation documentation.
I'd like to know :
Is the syntax no longer correct?
Is there a webpage somewhere that details the list of availble Types?
Whenever I run into an issue like this, I go to the source code. Here's the file for LayoutAnimation.js from the react-native source code. Based on this, I see a TypesEnum const declaration at line 25 looking like this:
const TypesEnum = {
spring: true,
linear: true,
easeInEaseOut: true,
easeIn: true,
easeOut: true,
keyboard: true,
};
I suspect that's why you are erring out - curveEaseInEaseOut is not a supported type. Choose one from the list above and I think you should be good to go. Hope this helps!

Data Testing in EmberJS and QUnit using fixtures

I have a simple ember application and I want to test it, without making server for API calls.
I've looked around a bunch and found this piece of code which helps tremendously. Problem is for testing I want to use the fixture adapter (makes sense, right?)
#store = Lfg.__container__.lookup('store:main')
Here is my model:
Lfg.Activity = DS.Model.extend
title: DS.attr('string')
people: DS.attr('number')
maxPeople: DS.attr('number')
host: DS.attr('string')
Then inside an Em.run => I do this
Lfg.reset()
container = new Ember.Container()
# These are my models... just one for now.
[
'activity'
].forEach (x,i) ->
container.register 'model:'+x, Lfg.get( Ember.String.classify(x) )
# It's essentially just: container.register("model:activity", Lfg.Activity)
#store = DS.Store.create
adapter: DS.FixtureAdapter.extend()
container: container
But I keep getting errors with the serializer. I tried adding the serializer but doesn't help. Do I need to container.register other things as well?
The error I get is TypeError: Cannot call method 'serialize' of undefined coming from mockJSON method, more specifically store.serializerFor(type) is returning null.
If I set store via store = Lfg.__container__.lookup('store:main') and then store.serializerFor(Lfg.Activity) it seems to work ok in the console -- is this not the same store? I want to use the one with the fixture adapter. I tried setting the serializer but that didn't help.
I prefer using something like mockjax to mock the api endpoints, then using qunit and the built in helpers provided by Ember and qunit
Here's an example of how to set up a simple json response
$.mockjax({
url: '/colors',
dataType: 'json',
responseText: {
colors:[
{
id: 1,
color: "red"
},
{
id: 2,
color: "green"
},
{
id: 3,
color: "blue"
}
]
}
});
And a test that would hit this endpoint
test("root lists 3 colors", function(){
var store = App.__container__.lookup('store:main');
var colors = store.find('color');
stop();
colors.then(function(arr){
start();
equal(arr.get('length'), 3, 'store returns 3 records');
});
});
http://emberjs.jsbin.com/wipo/3/edit

How to properly initialize the JSON store in Worklight 6.1

I am attempting to initalize the IBM Worklight JSON store as below:
//JSONStore jsonStoreCollection metadata
var jsonStoreCollection = {};
//JSONStore jsonStoreCollection metadata
var COLLECTION_NAME = 'people';
function wlCommonInit(){
// Create empty options to pass to
// the WL.JSONStore.init function
var options = {};
//Define the collection and list the search fields
jsonStoreCollection[COLLECTION_NAME] = {
searchFields : {name: 'string'},
};
//Initialize the JSON store collection
WL.JSONStore.init(jsonStoreCollection, options)
.then(function () {
console.log("Successfully Initialized the JSON store");
})
.fail(function (errorObject) {
console.log("JSON store init failed :( ");
});
}
But when I run this in my android emulator the logcat gives me the "JSON store init failed" message. And the following error:
[wl.jsonstore {"src":"initCollection", "err":-2,"msg":"PROVISION_TABLE_SEARCH_FIELDS_MISMATCH","col":"token","usr":"jsonstore","doc":{},"res":{}}
This implementation seems to be very much what is outlined in the documentation, however I cannot get it to initialize.
Can anyone tell me what I am doing wrong here?
The documentation with the error codes is here.
-2 PROVISION_TABLE_SEARCH_FIELDS_MISMATCH
Search fields are not dynamic. It is not possible to change search fields without calling
the destroy method or the removeCollection method in the WL.JSONStore
class before calling the init method with the new search fields. This
error can occur if you change the name or type of the search field.
For example: {key: 'string'} to {key: 'number'} or {myKey: 'string'}
to {theKey: 'string'}.
No need to uninstall the application, just follow the documentation and handle that error case by calling removeCollection or destroy. For example:
WL.JSONStore.init(...)
.then(function () {
//init was successful
})
.fail(function (error) {
//check for -2
//call removeCollection or destroy
//re-init with new search fields
});
You can always submit a feature request to make this easier.
If you have previously created a JSON store with the same name but with different initialization variables. You must uninstall the application.
After uninstalling you can re-deploy the application to the device and the JSON store will initialize as expected.
Since discovering this, I have seen the issue a couple more times as I made changes to the configuration of my JSON store in my Worklight application.

Get values from localStorage to use in Sencha Touch AJAX Proxy

In my Sencha Touch application I store some values in localStorage and they get stored just fine. Later I need to use those values for a request to a store and I need to pass those values as request headers. The code looks like the following:
Ext.define('AppName.store.storeName', {
extend: 'Ext.data.Store',
requires: [
'AppName.model.modelName'
],
config: {
model: 'AppName.model.modelName',
storeId: 'storeName',
proxy: {
type: 'ajax',
url: 'http://dynamic',
headers: {
auth_token: localStorage.getItem('activeUserToken'),
user_email: localStorage.getItem('userEMail')
},
reader: {
type: 'json'
}
}
}
});
However, both auth_token and user_email values are being returned as "undefined" when in Chrome developer tools I clearly see those values. Besides of that I access those values in many other places in my Sencha Touch application but can't do that in the store itself.
Could anybody please tell me what I'm doing wrong?
Thanks
I've solved this problem in the following way. Instead of passing the headers in the store I'm passing the headers during the request, before loading the store. Here's the code for that:
Ext.getStore('storeName').getProxy().setUrl(someURL);
Ext.getStore('storeName').getProxy().setHeaders(
{
"auth_token" : activeUserToken,
"user_email" : userEmail
}
);
Ext.getStore('storeName').load();

Sencha touch 2.0 : Store loading, first availability

I'm trying to figure out when a store is ready to be used within my app.
I figured from the doc that if I want to display information from my store, I should listen to the 'refresh' event of my store to get notified when it has been changed (and thus also when it is first loaded).
However, using the following example:
Ext.define('MyApp.store.Config', {
extend: 'Ext.data.Store',
config: {
autoLoad: true,
autoSync: true,
model: 'MyApp.model.Config',
listeners: {
refresh: function() {
console.log(Ext.StoreManager.get('Config').getAt(0))
}
}
} });
the 'console.log' gets called twice at startup, and it fails the first time (it seems that the Store is not loaded yet). My model uses a proxy (type ajax, and a json reader).
Could someone tell me how I should proceed to avoid this error?
Thanks!
I found the reason...
I was declaring the 'stores:['Config']' property both in my app.js and in on of my controllers.
Quite hard to spot but my mistake...