Any alternative for nesting observer in room database? - android-room

I'm quite new to programming!
I have solved the problem by following way.
Any alternative to NESTING is appreciated.
Thanks.
Using Kotlin with room database.
I get fine result by following way. But nesting for more than 3 times is not handy solution. I know I have to learn more..
observing and getting the dateString value
then passing it through second observer..
userViewModel.getUser(userId!!).observe(viewLifecycleOwner, Observer {user->
val dateStr = JSONObject(user.setting).getString("date")
payViewModel.getAllPayDate(sdf.parse(dateStr)).observe(viewLifecycleOwner,
Observer {pay->
//geting the ui related values here..
})
})

Related

I have a problem with the method removeChild

I'm new here on Stackoverflow, started programming in January, small own applications could already be implemented and now I have a problem with JavaScript with the removeChild method, because I don't know how to use this method with other methods and functions can combine or must write.
Thanks in advance
Not really sure what you are trying to do, your question should be a bit more specific.
Just as an example, say you want to remove all items from a list, here's an example of what could be used.
var element = document.getElementById("top");
while (element.firstChild) {
element.removeChild(element.firstChild);
}
If you simply want to delete one child you would need to know the parent's Id, it is done like so...
var d = document.getElementById("top");
var d_nested = document.getElementById("nested");
var throwawayNode = d.removeChild(d_nested);
you can try the W3School documentation if you'd like
https://www.w3schools.com/jsref/met_node_removechild.asp

Ember Sort my Records so the null for a column are retuned first

I want to filter and then sort my ember records such that the null records for a column are returned first. I'm not much familiar with ember and have a rails back ground.
filteredByData = myLeads.filterBy('status', 'open').filterBy('doNotCall', false).filterBy('phoneValid', true)
filtered = filteredByData.sortBy 'last_dialed_at', 'last_name', 'first_name', 'id'
Right now, my records are getting ordered according to the id.
What i want is to implement the NULLS LAST/FIRST from sql or postgres in any query (such a s SELECT * FROM t1 ORDER BY c1 DESC NULLS FIRST here in my sort so i get the records such that the last_dialed_atnull records come first.
I know the same can be implemented in rails like
Foo.order('last_dialed_at DESC NULLS FIRST') but i have no idea for same in Ember
Any help will be appreciated. Thanks in Advance.
P.S: I'll try to create a ember twiddle meanwhile to explain myself better.
Although you can resort to a SortableMixin/ArrayProxy, those are lower-level APIs than you should really need to use. sortBy works fine for a single value, but I generally use computed.sort when I need to sort multiple things. Take a look at the code and link in this answer https://stackoverflow.com/a/46788377/334913 they should get you going.
One of the common ways Ember suggests doing things is to do computed properties for each step (or set of steps) as it makes it far easier to reason about.
So I would do something along the lines of:
filteredLeads: Ember.computed('leads', function() {
return filteredResultsHere;
}),
sortDefinition: [], // put your entries from your SortableMixin here
sortedFilteredLeads: Ember.computed.sort('filteredLeads', 'sortDefinition'),
I solved my issue by using the Ember.SortableMixin instead of sortBy. I ended up with the following code and this worked perfectly for me.
leads = Ember.ArrayProxy.createWithMixins Ember.SortableMixin, content: filteredByData, sortProperties: ['lastDialedAt', 'firstName', 'lastName', 'id'], sortAscending: true
I'm not sure or much aware why this worked and the fundamentals to an extent that i can explain this behaviour. If there's any explanation for same from anyone, please feel free to put your answer below and i'll accept it as the answer.
Thanks

Should I use singletableview?

I'm learning about Django tables. I first wrote a basic example, here my view:
def people1(request):
table = PersonTable(Person.objects.filter(id=2))
RequestConfig(request).configure(table)
return render(request, 'people.html', {'table': table})
This way I've been able to easily display a table with a filter condition "filter(id=2))".
After that I found SingleTableView which is supposed to be an easier way to display database tables, as an example I wrote this view, which worked fine:
from django_tables2 import SingleTableView
class PersonList(SingleTableView):
template_name = 'ta07/comun.html'
model = Person
table_class = PersonTable
Questions are: how should I do to apply filters like in the first example? And is SingleTableView better than the basic way?
I'd say for now, you should only use it for the very basic use case. As soon as you need customizations from that, use your own.
Since filtering is a very common use case, I might consider adding that to the features of SingleTableView at some point. If you need it before that, feel free to open a pull request.

grails sort by date not working

I have domain object named Roll and on the list page i want to show the user all the Roll objects iterating through a list, sorted by entry date.
Here is the code i am using
[rollList: Roll.findAll(sort:"rollDate"){userid==uid}]
rollDate is a field inside the Roll object with data type java.util.Date
Any suggestion on why the output is not sorted by rollDate. When i iterate through the rollList on the gsp page it is not sorted.
Also, on the Roll domain object i have even put this code, but it's still not sorting.
static mapping = {
sort "rollDate"
}
Thank you.
Why aren't you using the dynamic finders?
Roll.findAllByUserid( uid, [ sort:"rollDate", order: 'desc'] )
should work.
The findAll( Map, Closure ) method appeared not a long time ago, perhaps it was not tested well...
You might need to use order in your query as well, then add order to it
[rollList: Roll.findAll(sort:"rollDate", order: 'desc'){userid==uid}]
After trying both the solutions mentioned it still didn't work. So i thought something might be wrong on the front end.
While researching more i found that since i was using jquery data tables it used to re order the sorting. The solutions i found was here
jQuery DataTable rows order
So both the answers above are correct. The issue was actually with jquery data tables.

Making improvements to code

I have been working on a magento module for sometime now (not because it is a large module, its my first and I really struggled with it). I now have it working, which I was really pleased with at first, but now I would like to improve it by increasing the reusability of the code.
While making my module I have looked at other modules to learn from them and have seen that many actions are only a line or two and I have tried keeping in with the skinny controller approach but failed, my example is as follows:
I have a function that get a users details that they have inputted into a custom form
protected function _setPostData()
{
$this->_salutation = $this->getRequest()->getPost('salutation');
$this->_f_name = $this->getRequest()->getPost('f_name');
$this->_l_name = $this->getRequest()->getPost('l_name');
$this->_email = $this->getRequest()->getPost('email');
$this->_emailAddressCheck = $this->getRequest()->getPost('emailAddressCheck');
$this->_gender = $this->getRequest()->getPost('gender');
$this->_country = $this->getRequest()->getPost('country');
$this->_pref_lang = $this->getRequest()->getPost('pref_lang');
}
I feel that this is not the correct way to do it and that there is a better way of achieving the same goal, as you can see this function gets the posts data and assigns it to attributes that i've set at the start of the class. I have several other examples that are very similar to the above and if someone could please offer some guidance on this one I am sure I will be able to work out the others
This example is held within the index action, should I put it in a helper as once it created correctly i am sure there will be a few occasions that I will be able to use it again?
you should put all the post data on an array and use it from there
$dataArray=$this->getRequest()->getPost();
$this->_salutation = $dataArray['salutation'];
$this->_f_name = $dataArray['f_name'];
$this->_l_name = $dataArray['l_name'];

Resources