I have a simple model:
Ext.define('MovieModel', {
extend : 'Ext.data.Model',
fields : [ {
name : 'Title',
mapping : '#title',
type : 'string'
} ],
proxy : {
type : 'ajax',
url : 'http://www.imdbapi.com/?r=xml&plot=full',
method : 'GET',
reader : {
type : 'xml',
record : 'movie'
}
}
});
But this code doesn't support cross domain policy. How could I solve it?
First of all get rid of r=xml param. Instead of ajax proxy use jsonp one:
proxy : {
type : 'jsonp',
url : 'http://www.imdbapi.com/?plot=full',
// jsonp uses its special method for retrieving data. So no need for the following row
//method : 'GET',
reader : {
type : 'json',
// the record param is used when data is nested construction
// which is not true in your case
//record : 'movie'
}
}
Here is demo.
Related
I am trying to get a document file from phone storage when button is pressed and than upload it server. But i don't know which library to use and how to do it.
If you are willing to use a library you have both React-native-fetch-blob or axios.
If React-native-fetch-blob you can do it like this:
RNFetchBlob.fetch('POST', 'http://www.example.com/upload-form', {
Authorization : "Bearer access-token",
otherHeader : "foo",
'Content-Type' : 'multipart/form-data',
}, [
// element with property `filename` will be transformed into `file` in form data
{ name : 'avatar', filename : 'avatar.png', data: binaryDataInBase64},
// custom content type
{ name : 'avatar-png', filename : 'avatar-png.png', type:'image/png', data: binaryDataInBase64},
// part file from storage
{ name : 'avatar-foo', filename : 'avatar-foo.png', type:'image/foo', data: RNFetchBlob.wrap(path_to_a_file)},
// elements without property `filename` will be sent as plain text
{ name : 'name', data : 'user'},
{ name : 'info', data : JSON.stringify({
mail : 'example#example.com',
tel : '12345678'
})},
]).then((resp) => {
// ...
}).catch((err) => {
// ...
})
You will hae to manage to get the file path from libraries like RNFS or even RNFetch blob.
https://github.com/wkh237/react-native-fetch-blob
You can use axios too (https://github.com/mzabriskie/axios), but I don't use it so I can't help you any further.
The difference between both is the way they send the data. RNFB uses the fetch api and goes down to native to get the Base64 encoding, axios works over XMLHttpRequests, which is more likely to be used in internet browsers.
Hope it helps.
My question is fairly simple. Say that I have a type mapping in an index that looks like this:
"mappings" : {
"post" : {
"analyzer" : "my_custom_analyzer",
"properties" : {
"body" : {
"type" : "string",
"store" : true
}
}
}
}
Note that I specified my_custom_analyzer as the analyzer for the type. When I search the body field without specifying an analyzer in the query, I expect my_custom_analyzer to be used. However, when I use the Analyze API to query the field:
curl http://localhost:9200/myindex/_analyze?field=post.body&text=test
It returns standard analysis results for string. When I specify the analyzer it works:
curl http://localhost:9200/myindex/_analyze?analyzer=my_custom_analyzer&text=test
My question is: why doesn't the Analyze API use the default type analyzer when I specify a field?
Analyzer is per string field.
You cant apply it over an object or nested object and hope all the fields under that object field will inherit that analyzer.
The right approach is as follows -
"mappings" : {
"post" : {
"properties" : {
"body" : {
"type" : "string",
"analyzer" : "my_custom_analyzer",
"store" : true
}
}
}
}
The reason the analyzer worked for analyzer API is because you have declared analyzer for that index.
If you want to define analyzer for all the string fields under a particular object ,you need to mention that in the type template. You can get more information about that here - http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/mapping-root-object-type.html#_dynamic_templates
I am uploading a video to Youtube and then attempting to add it to a playlist. The playlist insert is failing in a weird way.
Here is my code:
var options = {
'part' : 'snippet',
'snippet' : {
'playlistId' : playlistId,
'resourceId' : {
'kind' : 'youtube#video',
'videoId' : videoId
}
},
status : {
privacyStatus : 'unlisted'
}
};
console.log('options : ' + JSON.stringify(options));
youtube.playlistItems.insert(options, function(listErr, listResponse){
console.log(JSON.stringify(listErr));
console.log(JSON.stringify(listResponse));
});
I always get the exact same response:
{"errors":[{"domain":"youtube.playlistItem","reason":"playlistIdRequired","message":"Playlist id not specified."}],"code":400,"message":"Playlist id not specified."}
Anyone have any idea what I'm doing wrong? Any help will be much appreciated. I'm using googleapi Node.js sdk.
I was having a similar issue and inspected the source code and realised that the body of an API call should be under options.resource property. So your options object should look like the following:
var options = {
"part" : "snippet",
"resource" : {
"snippet" : {
"playlistId" : playlistId,
"resourceId" : {
"kind" : "youtube#video",
"videoId" : videoId
}
}
}
}
Also note that I've changed the object to use double-quotation marks, as options.resource is expected to be valid JSON. I've also removed the status property as it is not listed as a parameter on the API reference page - https://developers.google.com/youtube/v3/docs/playlistItems/insert
My aplication has this structure:
Project (model)
-> tracks (collection)
-> track (model)
-> clips (collection)
clip (model)
I need to fetch only parent project model. It will cause change of all data structure. I get JSON
{ "_id" : "123",
"name" : "name",
"tracks" : [ { "clips" : [ { "audioName" : "audio name",
"audioPath" : "audio/path.wav",
"duration" : 123,
"id" : "track0-1"
} ],
"mute" : false,
"name" : "track0",
"selected" : false,
"volume" : 100
},
{ "clips" : [ ],
"mute" : false,
"name" : "track1",
"selected" : false,
"volume" : 100
}
]
}
I have parse method:
parse: function (data) {
this.get('tracks').reset(data.tracks);
delete data.tracks;
return data;
}
I am not able to parse clips. In model track, attribute clips has behavior like javascript array instead of backbone model.
How can I parse clips?
parse is only used to parse responses from the server. So you won't be able to use it to create your clips collection.
So you may want to change the way you do that (maybe have a look at Backbone-relational, I think it deals with this kind of stuff). Here's a possible solution (to be put in your model):
initialize: function() {
this.listenTo(this, 'change:clips', this.onChangeClips);
// the rest of your stuff
},
onChangeClips: function() {
var clips = this.get('clips');
if(Object.prototype.toString.call(clips) === '[object Array]')
this.set('clips', new Clips(clips), {silent: true});
}
Source to test if array: Check if object is array?
Note: this will remove any reference to an existing collection (which you seem to have), so you may want to keep a reference to your collection in your model (like in a _clips attribute) to reset it with the new clips array.
Venue.update({_id : venue.id},
{
name : venue.name,
'contact.phone' : venue.contact.formattedPhone
}, {upsert: true}).exec()
In this code, if venue has no phone, Upsert operation is not done. How can I avoid this? I want to update that field if it is not null, but if null, just dont include that field.
Edit:
Venue.update({_id : venue.id},
{
name : venue.name,
'contact.phone' : ((!venue.contact.formattedPhone)?
'' : venue.contact.formattedPhone)
}, {upsert: true, safe:false}).exec()
This code works fine but this time, 'phone' fields are ''. What I want is, hiding the field if it is undefined.
Build up your update object programmatically to not include 'contact.phone' when not provided:
var update = {
name : venue.name
};
if (venue.contact.formattedPhone) {
update['contact.phone'] = venue.contact.formattedPhone;
}
Venue.update({_id : venue.id}, update, {upsert: true, safe:false}).exec();