![]() |
Re: Help me to code for Sailfish OS
Quote:
The way to learn is to read the file and see what changes the patch is making, just like @coderus said. :) |
Re: Help me to code for Sailfish OS
Hi all,
I've made myself a basic weather application, it uses the OpenWeatherMap.org API for data. I would like to know how to enter my Weather API URL to my `weather.js` file using Dialog, but I'm unsure how to do it. I have played around with the example from Jolla, but I don't know quite what I'm doing......help! :) The weather.js file uses XmlHttpRequest to fetch the data. Code:
function requestWeatherData(cntr) { |
Re: Help me to code for Sailfish OS
is your API key embedded to url? Then you can just do this:
Code:
let url = 'https.//www.example.com?api_key=' + API_key; I would then use fetch api to get the response: Code:
let response = await fetch(url); |
Re: Help me to code for Sailfish OS
Quote:
|
Re: Help me to code for Sailfish OS
Ah, right. Didn't know that. I suggested fetch because it's so easy. Let me check how to do it with xmlhttprequest...
|
Re: Help me to code for Sailfish OS
Found from here: https://openweathermap.org/forecast5#call
Code:
api.openweathermap.org/data/2.5/forecast?zip={zip code},{country code}&appid={your api key} EDIT: I had to check, but XMLHttpRequest doesn't allow cross-site requests, so it wont work without modifications. With a short look, it seems there's CORS and JSONP to circumvent the restriction, but I don't know if they're supported on SFOS, and this is also something I have no experience implementing. I would try it anyways, though. Maybe there's no restrictions when using it when you are not actually doing this js stuff with a browser attached. |
Re: Help me to code for Sailfish OS
1 Attachment(s)
Is there a way to force a ListModel to refresh, when the database records have been changed?
I have a page, where the ListModel is filled by a JS function getting a SELECT from a SQLite database. It is a list of letters, with a possible value, e.g. A="3", B="". After some experiments with TextFields I chose for Buttons. Then a Dialog opens, where the value can be changed. However, after the change, the Button does not show the new value of the letter. Can I force an update? Maybe by a signal from the PageStack that the current page has become visible again? The Button is now configured like: Code:
Button { |
Re: Help me to code for Sailfish OS
how do you work with model?
|
Re: Help me to code for Sailfish OS
Thanks for helping, coderus!
The simplified code looks like this. Code:
import QtQuick 2.0 On clicking the button, the Dialog in "LetterPage.qml" provides the possibility to enter a value for the letter. Then onDone, the value is stored in the database. After the pop() I don't know how to update the ListModel from the updated database. This morning I thought of a work-around, but a proper method would be nice. |
Re: Help me to code for Sailfish OS
Hm. Work-around is not working.
|
All times are GMT. The time now is 09:50. |
vBulletin® Version 3.8.8