Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
In my Flutter app, I want sorted data to depend upon the last date which is present in medicine list for a particular user, so how can I write my Firebase query?
I'm using Firebase Firestore.
Try something like this (code has not yet been tested):
List<dynamic> getMedicinesSorted() async {
final snapshot = await FirebaseFirestore.instance
.collection('users/tnzdrlpLD1hfJJ6o8iMV/MedicinesList')
.get();
final sorted = snapshot.docs.sort((docA, docB) =>
new DateTime.fromMicrosecondsSinceEpoch(docA.data()['Last_Date']).compareTo(
new DateTime.fromMicrosecondsSinceEpoch(docB.data()['Last_Date'])
)
);
return sorted;
}
[enter image description here][1]
image
[1]: https://i.stack.imgur.com/C6qy8.jpg
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 1 year ago.
Improve this question
I wanted to know how to add a field in a certain user uid
So I'd like to add another field like Address for the currentUser "Rowan Whitethorn". How can I do this?
Currently, i could add another field but it creates another documents.
const userRef = firestore.collection('users').doc(currentUser.uid);
async function addAddress() {
const res = await userRef.set({
'Address' : 'Ayala'
}, { merge : true});
}
Firestore documentation describes a feature "merge", where you would typically create a new doc with using ".set", but then pass a parameter "merge" which tells firebase not to overwrite your doc data, in your case it would be something like:
const userRef = db.collection('users').doc(doc_id);
const res = await userRef.set({
'some_new_field': 'value'
}, { merge: true });
Here's the link for their documentation, you will find a similar example under "merge": https://firebase.google.com/docs/firestore/manage-data/add-data
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
I have json format data that I am retrieving from my ORDS server and it looks like this:
{"items":[{"cust_code":"C00013","cust_name":"Holmes","cust_city":"London
","working_area":"London","cust_country":"UK","grade":2,"opening_amt":6000,"receive_amt":5000,"payment_amt":7000,"outstanding_amt":4000,"phone_no":"BBBBBBB","agent_code":"A003
"},{"cust_code":"C00001","cust_name":"Micheal","cust_city":"New York
","working_area":"New
York","cust_country":"USA","grade":2,"opening_amt":3000,"receive_amt":5000,"payment_amt":2000,"outstanding_amt":6000,"phone_no":"CCCCCCC","agent_code":"A008
"},{"cust_code":"C00020","cust_name":"Albert","cust_city":"New York
","working_area":"New
York","cust_country":"USA","grade":3,"opening_amt":5000,"receive_amt":7000,"payment_amt":6000,"outstanding_amt":6000,"phone_no":"BBBBSBB","agent_code":"A008
"},{"cust_code":"C00025","cust_name":"Ravindran","cust_city":"Bangalore
","working_area":"Bangalore","cust_country":"India","grade":2,"opening_amt":5000,"receive_amt":7000,"payment_amt":4000,"outstanding_amt":8000,"phone_no":"AVAVAVA","agent_code":"A011
"},{"cust_code":"C00015","cust_name":"Stuart","cust_city":"London
","working_area":"London","cust_country":"UK","grade":1,"opening_amt":6000,"receive_amt":8000,"payment_amt":3000,"outstanding_amt":11000,"phone_no":"GFSGERS","agent_code":"A003
"}],"hasMore":false,"limit":25,"offset":0,"count":5,"links":[{"rel":"self","href":"http://localhost:9000/ords/demo/customers/getAll/"},{"rel":"describedby","href":"http://localhost:9000/ords/demo/metadata-catalog/customers/getAll/"},{"rel":"first","href":"http://localhost:9000/ords/demo/customers/getAll/"}]}
so I was wondering if there is a way to to break down the items part and to put it in a tables using anguler.
I tried to use this way in my ts file:
http.get('http://localhost:9000/ords/demo/customers/getAll/')
.subscribe(data => this.items = data);
But I keep getting this error:
Error: Error trying to diff '[object Object]'. Only arrays and iterables are allowed
The array you want is in the items property so you have to do
http.get('http://localhost:9000/ords/demo/customers/getAll/')
.subscribe(data => this.items = data.items);
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 4 years ago.
Improve this question
This is my code:
func didMarkAsFavoriteContact(_ contact: Contact) {
var outerIndex: Array.Index? = nil
}
It is not very clear what you are trying to do but if you just want to initialize something that can serve as an index you can do something like this:
var outerIndex: Int? = nil
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 4 years ago.
Improve this question
I want to store the following data in Firebase and use the same in Ionic 3 but I did not find any clear documentation that could help me. Can someone give me a way?
This is an example of array on home.ts
initializeItems() {
this.items = [
{id: '1', nome:'Abaéte', rua:'Moacir', cidade:'Capão da Canoa', bairro:'Centro', numero:'396', ano:'1964', aptos:'55', adm:'Adsel', zelador:'Hugo', contato1:'(51) 0 0000 - 0000', contato2: '(51) 0000 - 0000', imagem:'assets/img/Abaete-min.jpg'},
];
And this a image the App list
Your sample shows an object not an array. Yes you can push objects to Firebase.
I'm assuming you're using angularfire2 with Ionic.
const myObject = {
id: '1',
nome:'Abaéte',
rua:'Moacir',
cidade:'Capão da Canoa',
bairro:'Centro',
numero:'396',
ano:'1964',
aptos:'55',
adm:'Adsel',
zelador:'Hugo', c
ontato1:'(51) 0 0000 - 0000',
contato2: '(51) 0000 - 0000',
imagem:'assets/img/5yDViHGwTkaJSEDkHyqS_Abaete.JPG'
}
this.db.list('/some/path').push(myObject)
.then(resp => {
console.log('All Saved!');
});
If you do want to push arrays you should take a look at the Firebase Blog. It discourages saving arrays, but instead using the push method to generate a unique ID for each array item.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I have 2 select boxes in my app and they are populated from db, when I choose a value from first select box, second select box is populate via ajax. this scenarion works great. but as the values in select boxes are static I didn't want populate them from db, I think use for this a file is more usefull and good for app performance. so how I can populate them from file (json, xml, etc.)? first select box to the second is one-to-many
This sounds like a lot of work since your going to have to populate the text files from db. Infact its end result will be in effect no different to a caching solution.http://mrdustmite.blogspot.co.uk/2010/09/simple-ehcache-in-grails.html?m=1
The mentioned plugin above generates primary/secondary values from as JSON values..
https://github.com/vahidhedayati/ajaxdependancyselection/blob/master/grails-app/services/ajaxdependancyselection/AutoCompleteService.groovy
def selectSecondary(params) {
if (params.domain2) {
def domainClass = grailsApplication?.getDomainClass(params?.domain2)?.clazz
def query = {
eq params.bindid, params.id.toLong()
projections {
property(params.collectField)
property(params.searchField)
}
order(params.searchField)
}
def results =domainClass.createCriteria().list(query)
def primarySelectList = []
results.each {
def primaryMap = [:]
primaryMap.put('id', it[0])
primaryMap.put('name', it[1])
primarySelectList.add(primaryMap)
}
return primarySelectList as JSON
}
}
https://github.com/vahidhedayati/ajaxdependancyselection/blob/master/grails-app/taglib/ajaxdependancyselection/AutoCompleteTagLib.groovy
def gsattrs=['optionKey' : "${attrs.collectField}" , 'optionValue': "${attrs.searchField}", 'id': "${attrs.id}", 'value': "${attrs.value}", 'name': "${name}"]
gsattrs['from'] = primarylist
gsattrs['noSelection'] =attrs.noSelection
gsattrs['onchange'] = "${remoteFunction(controller:''+attrs.controller+'', action:''+attrs.action+'', params:'\'id=\' + escape(this.value) +\'&setId='+attrs.setId+'&bindid='+ attrs.bindid+'&collectField='+attrs.collectField2+'&searchField='+attrs.searchField2+'&domain2='+attrs.domain2+'&controller='+attrs.controller+'\'',onSuccess:''+attrs.id+'Update(data)')}"
def link = ['action': attrs.action , 'controller': attrs.controller ]
out<< g.select(gsattrs)
You should be able to use the functionality to reproduce the same effect from a text file if you so wish to go down this route...