An attempt to create a synchronization of Sencha-Touch-2 applications with the Node.js server; code below. The server uses a different port on the same IP address, so this is cross-domain. (The server uses Mongoose to communicate with MongoDB content (not shown))
I read this forum elsewhere for a couple of days, but it seems I'm stuck. Any help would be greatly appreciated.
Node.js and restore the server
var server = restify.createServer({ name: 'Server', key: fs.readFileSync(root+'/'+'privatekey.pem'), certificate: fs.readFileSync(root+'/'+'certificate.pem') }); server.use(restify.bodyParser()); server.use(restify.queryParser()); function getMessages(req, res, next) { Model.find(function (err,data) { res.setHeader('Content-Type', 'text/javascript;charset=UTF-8'); res.send(req.query["callback"] + '({"records":' + JSON.stringify(data) + '});'); }); } function postMessage(req, res, next) {
Sencha Touch 2
Model
Ext.define('ATApp.model.User', { extend: 'Ext.data.Model', config: { fields: [ { name: 'name', type: 'string' }, { name: 'description', type: 'string' }, { name: 'date', type: 'date' }, { name: '_id' } ...
Score
Ext.define('ATApp.store.Data', { extend: 'Ext.data.Store', requires: [ 'ATApp.model.User', 'Ext.data.proxy.JsonP' ], config: { autoLoad: true, model: 'ATApp.model.User', storeId: 'Data', proxy: { type: 'jsonp', model: 'ATApp.model.User', url: 'https://192.168.2.45:13017/atapp', reader: { type: 'json', idProperty: '_id', rootProperty: 'records', useSimpleAccessors: true }, writer: { type: 'json', allowSingle: false, encode: true, idProperty: '_id', rootProperty: 'records' ...
controller
onNewDataRecord: function (view) { console.log('newDataRecord'); var now = new Date(); var record = Ext.create('ATApp.model.User', { date: now, name: '..', description: '..' }); var store = Ext.data.StoreManager.lookup('Data') record.setProxy(store.getProxy()); store.add(record); this.activateEditor(record); }, ...