Problem when using the same view in tabview along with observable
Ok, i have a tabview with some pages in it, the first and 2nd page fetch data from the web and displas it in form of a gridview . Since the UI is exactily the same in both pages i tought of just using one .xml file with it´s respective .js /.ts file. and using frames in the tabview to display the same page with some condition in the frame component, like
<Frame id="firstFrame" defaultPage="home/home-page" isPage='1' />
and then in my respective .js page use something like
function pageLoaded(args) {
page = args.object;
condition = page.frame.isPage
viewModel = new Observable();
viewModel.set("items", '');
page.bindingContext = viewModel;};
where i store the "condition" in a global scope variable. and use it wherever there is come conditional rendering needed. I also store viewmodel in a global scope.
IT WORKS FINE... kinda... you see, the 2 pages are Suposed to display different data. but for dome reason, the first page displays an empty page [with no data], and the second wone works fine..
More strange, when i call a function to update the data in the 1st page, it updates it in page 2, and the page one is still blank, if i restar the app, and call the same function in page 2 (remember they are the same page), it updates page one sometimes.
Could it be that both pages are using the same Observable (items)? , if that so, how i´m supposed to bind the Observable to their respective pages?
Oh i should also menction that i use "exports.functioname = functionname" to call the function. It might be that maybe? i see that the appropiate way to do it is to bind it inside the "page-view-model" file. Could it be that?
nativescript
add a comment |
Ok, i have a tabview with some pages in it, the first and 2nd page fetch data from the web and displas it in form of a gridview . Since the UI is exactily the same in both pages i tought of just using one .xml file with it´s respective .js /.ts file. and using frames in the tabview to display the same page with some condition in the frame component, like
<Frame id="firstFrame" defaultPage="home/home-page" isPage='1' />
and then in my respective .js page use something like
function pageLoaded(args) {
page = args.object;
condition = page.frame.isPage
viewModel = new Observable();
viewModel.set("items", '');
page.bindingContext = viewModel;};
where i store the "condition" in a global scope variable. and use it wherever there is come conditional rendering needed. I also store viewmodel in a global scope.
IT WORKS FINE... kinda... you see, the 2 pages are Suposed to display different data. but for dome reason, the first page displays an empty page [with no data], and the second wone works fine..
More strange, when i call a function to update the data in the 1st page, it updates it in page 2, and the page one is still blank, if i restar the app, and call the same function in page 2 (remember they are the same page), it updates page one sometimes.
Could it be that both pages are using the same Observable (items)? , if that so, how i´m supposed to bind the Observable to their respective pages?
Oh i should also menction that i use "exports.functioname = functionname" to call the function. It might be that maybe? i see that the appropiate way to do it is to bind it inside the "page-view-model" file. Could it be that?
nativescript
1
Can you create a sample with Playground?
– Manoj
Nov 16 '18 at 21:41
I managed to recreate this on playground play.nativescript.org/?template=play-js&id=zgeCrN , i think that it has something to do with async/await, because when i update the observable statically like "viewModel.set("items", The Page is ' + condition);" , it works as expected.
– ValdaXD
Nov 17 '18 at 15:13
A workaround that i´ve found is to use 2 viewmodels and update them according to the page . it makes the code a little bit messy but i guess it works. However i would like to know what would be the correct approach to avoid this when reusing pages on a tabview.
– ValdaXD
Nov 17 '18 at 15:16
Found another workaround. And is NOT using global variables . play.nativescript.org/?template=play-js&id=zgeCrN&v=2 that works as expected. but it sucks so much that the variable binding is not really binded to their own page , instead is binded to the global .js file. I guess it´s the way Nativescript works "<For each XML file that NativeScript parses, the framework also looks for a JavaScript or TypeScript file with the same name and executes the business logic inside it.>" in docs.nativescript.org/ui/basics.
– ValdaXD
Nov 17 '18 at 15:28
add a comment |
Ok, i have a tabview with some pages in it, the first and 2nd page fetch data from the web and displas it in form of a gridview . Since the UI is exactily the same in both pages i tought of just using one .xml file with it´s respective .js /.ts file. and using frames in the tabview to display the same page with some condition in the frame component, like
<Frame id="firstFrame" defaultPage="home/home-page" isPage='1' />
and then in my respective .js page use something like
function pageLoaded(args) {
page = args.object;
condition = page.frame.isPage
viewModel = new Observable();
viewModel.set("items", '');
page.bindingContext = viewModel;};
where i store the "condition" in a global scope variable. and use it wherever there is come conditional rendering needed. I also store viewmodel in a global scope.
IT WORKS FINE... kinda... you see, the 2 pages are Suposed to display different data. but for dome reason, the first page displays an empty page [with no data], and the second wone works fine..
More strange, when i call a function to update the data in the 1st page, it updates it in page 2, and the page one is still blank, if i restar the app, and call the same function in page 2 (remember they are the same page), it updates page one sometimes.
Could it be that both pages are using the same Observable (items)? , if that so, how i´m supposed to bind the Observable to their respective pages?
Oh i should also menction that i use "exports.functioname = functionname" to call the function. It might be that maybe? i see that the appropiate way to do it is to bind it inside the "page-view-model" file. Could it be that?
nativescript
Ok, i have a tabview with some pages in it, the first and 2nd page fetch data from the web and displas it in form of a gridview . Since the UI is exactily the same in both pages i tought of just using one .xml file with it´s respective .js /.ts file. and using frames in the tabview to display the same page with some condition in the frame component, like
<Frame id="firstFrame" defaultPage="home/home-page" isPage='1' />
and then in my respective .js page use something like
function pageLoaded(args) {
page = args.object;
condition = page.frame.isPage
viewModel = new Observable();
viewModel.set("items", '');
page.bindingContext = viewModel;};
where i store the "condition" in a global scope variable. and use it wherever there is come conditional rendering needed. I also store viewmodel in a global scope.
IT WORKS FINE... kinda... you see, the 2 pages are Suposed to display different data. but for dome reason, the first page displays an empty page [with no data], and the second wone works fine..
More strange, when i call a function to update the data in the 1st page, it updates it in page 2, and the page one is still blank, if i restar the app, and call the same function in page 2 (remember they are the same page), it updates page one sometimes.
Could it be that both pages are using the same Observable (items)? , if that so, how i´m supposed to bind the Observable to their respective pages?
Oh i should also menction that i use "exports.functioname = functionname" to call the function. It might be that maybe? i see that the appropiate way to do it is to bind it inside the "page-view-model" file. Could it be that?
nativescript
nativescript
asked Nov 16 '18 at 21:34
ValdaXDValdaXD
4019
4019
1
Can you create a sample with Playground?
– Manoj
Nov 16 '18 at 21:41
I managed to recreate this on playground play.nativescript.org/?template=play-js&id=zgeCrN , i think that it has something to do with async/await, because when i update the observable statically like "viewModel.set("items", The Page is ' + condition);" , it works as expected.
– ValdaXD
Nov 17 '18 at 15:13
A workaround that i´ve found is to use 2 viewmodels and update them according to the page . it makes the code a little bit messy but i guess it works. However i would like to know what would be the correct approach to avoid this when reusing pages on a tabview.
– ValdaXD
Nov 17 '18 at 15:16
Found another workaround. And is NOT using global variables . play.nativescript.org/?template=play-js&id=zgeCrN&v=2 that works as expected. but it sucks so much that the variable binding is not really binded to their own page , instead is binded to the global .js file. I guess it´s the way Nativescript works "<For each XML file that NativeScript parses, the framework also looks for a JavaScript or TypeScript file with the same name and executes the business logic inside it.>" in docs.nativescript.org/ui/basics.
– ValdaXD
Nov 17 '18 at 15:28
add a comment |
1
Can you create a sample with Playground?
– Manoj
Nov 16 '18 at 21:41
I managed to recreate this on playground play.nativescript.org/?template=play-js&id=zgeCrN , i think that it has something to do with async/await, because when i update the observable statically like "viewModel.set("items", The Page is ' + condition);" , it works as expected.
– ValdaXD
Nov 17 '18 at 15:13
A workaround that i´ve found is to use 2 viewmodels and update them according to the page . it makes the code a little bit messy but i guess it works. However i would like to know what would be the correct approach to avoid this when reusing pages on a tabview.
– ValdaXD
Nov 17 '18 at 15:16
Found another workaround. And is NOT using global variables . play.nativescript.org/?template=play-js&id=zgeCrN&v=2 that works as expected. but it sucks so much that the variable binding is not really binded to their own page , instead is binded to the global .js file. I guess it´s the way Nativescript works "<For each XML file that NativeScript parses, the framework also looks for a JavaScript or TypeScript file with the same name and executes the business logic inside it.>" in docs.nativescript.org/ui/basics.
– ValdaXD
Nov 17 '18 at 15:28
1
1
Can you create a sample with Playground?
– Manoj
Nov 16 '18 at 21:41
Can you create a sample with Playground?
– Manoj
Nov 16 '18 at 21:41
I managed to recreate this on playground play.nativescript.org/?template=play-js&id=zgeCrN , i think that it has something to do with async/await, because when i update the observable statically like "viewModel.set("items", The Page is ' + condition);" , it works as expected.
– ValdaXD
Nov 17 '18 at 15:13
I managed to recreate this on playground play.nativescript.org/?template=play-js&id=zgeCrN , i think that it has something to do with async/await, because when i update the observable statically like "viewModel.set("items", The Page is ' + condition);" , it works as expected.
– ValdaXD
Nov 17 '18 at 15:13
A workaround that i´ve found is to use 2 viewmodels and update them according to the page . it makes the code a little bit messy but i guess it works. However i would like to know what would be the correct approach to avoid this when reusing pages on a tabview.
– ValdaXD
Nov 17 '18 at 15:16
A workaround that i´ve found is to use 2 viewmodels and update them according to the page . it makes the code a little bit messy but i guess it works. However i would like to know what would be the correct approach to avoid this when reusing pages on a tabview.
– ValdaXD
Nov 17 '18 at 15:16
Found another workaround. And is NOT using global variables . play.nativescript.org/?template=play-js&id=zgeCrN&v=2 that works as expected. but it sucks so much that the variable binding is not really binded to their own page , instead is binded to the global .js file. I guess it´s the way Nativescript works "<For each XML file that NativeScript parses, the framework also looks for a JavaScript or TypeScript file with the same name and executes the business logic inside it.>" in docs.nativescript.org/ui/basics.
– ValdaXD
Nov 17 '18 at 15:28
Found another workaround. And is NOT using global variables . play.nativescript.org/?template=play-js&id=zgeCrN&v=2 that works as expected. but it sucks so much that the variable binding is not really binded to their own page , instead is binded to the global .js file. I guess it´s the way Nativescript works "<For each XML file that NativeScript parses, the framework also looks for a JavaScript or TypeScript file with the same name and executes the business logic inside it.>" in docs.nativescript.org/ui/basics.
– ValdaXD
Nov 17 '18 at 15:28
add a comment |
1 Answer
1
active
oldest
votes
Looking at your code, what you are facing is totally expected. The variable named condition
is not specific to the page instance so it just retains the last value assigned to it.
When Page 2 is loaded the condition
variable is overwritten with new value and never updated again.
This should be the answer logically. But it seems that the binding happens, and works, the word that breaks the binding is the use of "await" , check this playground, it works as expected if i remove the fetched data, and even works with global variables. play.nativescript.org/?template=play-js&id=zgeCrN&v=5
– ValdaXD
Nov 17 '18 at 20:02
It's not the await that breaks, await is nothing but execute a promise and return the value. It's still logically, when you use fetch data, it hits remote url and waits for response and even before it gets back with response the second page gets loaded and the condition value is updated. Without fetch data, your log is executed immediately before second page loads as it wouldn't have to wait for anything.
– Manoj
Nov 17 '18 at 21:38
Yeah, i managed to do it with settimeout() instead of await, so you are right. ¿any idea how can i bind the variable "condition" to the current page it´s declared? (to avoid overwriting) , i can´t manage to find the solution to that, some suggest using the module pattern but i´ve tried and it doesnt work ;-;
– ValdaXD
Nov 17 '18 at 22:01
If you don't want to overwrite anything, then it's wise to keep everything specific to each instance, store them in view model.
– Manoj
Nov 17 '18 at 22:06
Yeah i´m doing that , but then how i´m supposed to get the reference to the viewmodel ? ;_; if i store it in a variable then it´s gonna overwrite. I´m gonna try using the frame module to get the frame dinamically and then store the page inside it and store it in the viewmodel . It seems odd but i think thats the way to avoid this. Thanks!! c:
– ValdaXD
Nov 17 '18 at 22:35
|
show 1 more comment
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53345723%2fproblem-when-using-the-same-view-in-tabview-along-with-observable%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Looking at your code, what you are facing is totally expected. The variable named condition
is not specific to the page instance so it just retains the last value assigned to it.
When Page 2 is loaded the condition
variable is overwritten with new value and never updated again.
This should be the answer logically. But it seems that the binding happens, and works, the word that breaks the binding is the use of "await" , check this playground, it works as expected if i remove the fetched data, and even works with global variables. play.nativescript.org/?template=play-js&id=zgeCrN&v=5
– ValdaXD
Nov 17 '18 at 20:02
It's not the await that breaks, await is nothing but execute a promise and return the value. It's still logically, when you use fetch data, it hits remote url and waits for response and even before it gets back with response the second page gets loaded and the condition value is updated. Without fetch data, your log is executed immediately before second page loads as it wouldn't have to wait for anything.
– Manoj
Nov 17 '18 at 21:38
Yeah, i managed to do it with settimeout() instead of await, so you are right. ¿any idea how can i bind the variable "condition" to the current page it´s declared? (to avoid overwriting) , i can´t manage to find the solution to that, some suggest using the module pattern but i´ve tried and it doesnt work ;-;
– ValdaXD
Nov 17 '18 at 22:01
If you don't want to overwrite anything, then it's wise to keep everything specific to each instance, store them in view model.
– Manoj
Nov 17 '18 at 22:06
Yeah i´m doing that , but then how i´m supposed to get the reference to the viewmodel ? ;_; if i store it in a variable then it´s gonna overwrite. I´m gonna try using the frame module to get the frame dinamically and then store the page inside it and store it in the viewmodel . It seems odd but i think thats the way to avoid this. Thanks!! c:
– ValdaXD
Nov 17 '18 at 22:35
|
show 1 more comment
Looking at your code, what you are facing is totally expected. The variable named condition
is not specific to the page instance so it just retains the last value assigned to it.
When Page 2 is loaded the condition
variable is overwritten with new value and never updated again.
This should be the answer logically. But it seems that the binding happens, and works, the word that breaks the binding is the use of "await" , check this playground, it works as expected if i remove the fetched data, and even works with global variables. play.nativescript.org/?template=play-js&id=zgeCrN&v=5
– ValdaXD
Nov 17 '18 at 20:02
It's not the await that breaks, await is nothing but execute a promise and return the value. It's still logically, when you use fetch data, it hits remote url and waits for response and even before it gets back with response the second page gets loaded and the condition value is updated. Without fetch data, your log is executed immediately before second page loads as it wouldn't have to wait for anything.
– Manoj
Nov 17 '18 at 21:38
Yeah, i managed to do it with settimeout() instead of await, so you are right. ¿any idea how can i bind the variable "condition" to the current page it´s declared? (to avoid overwriting) , i can´t manage to find the solution to that, some suggest using the module pattern but i´ve tried and it doesnt work ;-;
– ValdaXD
Nov 17 '18 at 22:01
If you don't want to overwrite anything, then it's wise to keep everything specific to each instance, store them in view model.
– Manoj
Nov 17 '18 at 22:06
Yeah i´m doing that , but then how i´m supposed to get the reference to the viewmodel ? ;_; if i store it in a variable then it´s gonna overwrite. I´m gonna try using the frame module to get the frame dinamically and then store the page inside it and store it in the viewmodel . It seems odd but i think thats the way to avoid this. Thanks!! c:
– ValdaXD
Nov 17 '18 at 22:35
|
show 1 more comment
Looking at your code, what you are facing is totally expected. The variable named condition
is not specific to the page instance so it just retains the last value assigned to it.
When Page 2 is loaded the condition
variable is overwritten with new value and never updated again.
Looking at your code, what you are facing is totally expected. The variable named condition
is not specific to the page instance so it just retains the last value assigned to it.
When Page 2 is loaded the condition
variable is overwritten with new value and never updated again.
answered Nov 17 '18 at 16:05
ManojManoj
5,4832921
5,4832921
This should be the answer logically. But it seems that the binding happens, and works, the word that breaks the binding is the use of "await" , check this playground, it works as expected if i remove the fetched data, and even works with global variables. play.nativescript.org/?template=play-js&id=zgeCrN&v=5
– ValdaXD
Nov 17 '18 at 20:02
It's not the await that breaks, await is nothing but execute a promise and return the value. It's still logically, when you use fetch data, it hits remote url and waits for response and even before it gets back with response the second page gets loaded and the condition value is updated. Without fetch data, your log is executed immediately before second page loads as it wouldn't have to wait for anything.
– Manoj
Nov 17 '18 at 21:38
Yeah, i managed to do it with settimeout() instead of await, so you are right. ¿any idea how can i bind the variable "condition" to the current page it´s declared? (to avoid overwriting) , i can´t manage to find the solution to that, some suggest using the module pattern but i´ve tried and it doesnt work ;-;
– ValdaXD
Nov 17 '18 at 22:01
If you don't want to overwrite anything, then it's wise to keep everything specific to each instance, store them in view model.
– Manoj
Nov 17 '18 at 22:06
Yeah i´m doing that , but then how i´m supposed to get the reference to the viewmodel ? ;_; if i store it in a variable then it´s gonna overwrite. I´m gonna try using the frame module to get the frame dinamically and then store the page inside it and store it in the viewmodel . It seems odd but i think thats the way to avoid this. Thanks!! c:
– ValdaXD
Nov 17 '18 at 22:35
|
show 1 more comment
This should be the answer logically. But it seems that the binding happens, and works, the word that breaks the binding is the use of "await" , check this playground, it works as expected if i remove the fetched data, and even works with global variables. play.nativescript.org/?template=play-js&id=zgeCrN&v=5
– ValdaXD
Nov 17 '18 at 20:02
It's not the await that breaks, await is nothing but execute a promise and return the value. It's still logically, when you use fetch data, it hits remote url and waits for response and even before it gets back with response the second page gets loaded and the condition value is updated. Without fetch data, your log is executed immediately before second page loads as it wouldn't have to wait for anything.
– Manoj
Nov 17 '18 at 21:38
Yeah, i managed to do it with settimeout() instead of await, so you are right. ¿any idea how can i bind the variable "condition" to the current page it´s declared? (to avoid overwriting) , i can´t manage to find the solution to that, some suggest using the module pattern but i´ve tried and it doesnt work ;-;
– ValdaXD
Nov 17 '18 at 22:01
If you don't want to overwrite anything, then it's wise to keep everything specific to each instance, store them in view model.
– Manoj
Nov 17 '18 at 22:06
Yeah i´m doing that , but then how i´m supposed to get the reference to the viewmodel ? ;_; if i store it in a variable then it´s gonna overwrite. I´m gonna try using the frame module to get the frame dinamically and then store the page inside it and store it in the viewmodel . It seems odd but i think thats the way to avoid this. Thanks!! c:
– ValdaXD
Nov 17 '18 at 22:35
This should be the answer logically. But it seems that the binding happens, and works, the word that breaks the binding is the use of "await" , check this playground, it works as expected if i remove the fetched data, and even works with global variables. play.nativescript.org/?template=play-js&id=zgeCrN&v=5
– ValdaXD
Nov 17 '18 at 20:02
This should be the answer logically. But it seems that the binding happens, and works, the word that breaks the binding is the use of "await" , check this playground, it works as expected if i remove the fetched data, and even works with global variables. play.nativescript.org/?template=play-js&id=zgeCrN&v=5
– ValdaXD
Nov 17 '18 at 20:02
It's not the await that breaks, await is nothing but execute a promise and return the value. It's still logically, when you use fetch data, it hits remote url and waits for response and even before it gets back with response the second page gets loaded and the condition value is updated. Without fetch data, your log is executed immediately before second page loads as it wouldn't have to wait for anything.
– Manoj
Nov 17 '18 at 21:38
It's not the await that breaks, await is nothing but execute a promise and return the value. It's still logically, when you use fetch data, it hits remote url and waits for response and even before it gets back with response the second page gets loaded and the condition value is updated. Without fetch data, your log is executed immediately before second page loads as it wouldn't have to wait for anything.
– Manoj
Nov 17 '18 at 21:38
Yeah, i managed to do it with settimeout() instead of await, so you are right. ¿any idea how can i bind the variable "condition" to the current page it´s declared? (to avoid overwriting) , i can´t manage to find the solution to that, some suggest using the module pattern but i´ve tried and it doesnt work ;-;
– ValdaXD
Nov 17 '18 at 22:01
Yeah, i managed to do it with settimeout() instead of await, so you are right. ¿any idea how can i bind the variable "condition" to the current page it´s declared? (to avoid overwriting) , i can´t manage to find the solution to that, some suggest using the module pattern but i´ve tried and it doesnt work ;-;
– ValdaXD
Nov 17 '18 at 22:01
If you don't want to overwrite anything, then it's wise to keep everything specific to each instance, store them in view model.
– Manoj
Nov 17 '18 at 22:06
If you don't want to overwrite anything, then it's wise to keep everything specific to each instance, store them in view model.
– Manoj
Nov 17 '18 at 22:06
Yeah i´m doing that , but then how i´m supposed to get the reference to the viewmodel ? ;_; if i store it in a variable then it´s gonna overwrite. I´m gonna try using the frame module to get the frame dinamically and then store the page inside it and store it in the viewmodel . It seems odd but i think thats the way to avoid this. Thanks!! c:
– ValdaXD
Nov 17 '18 at 22:35
Yeah i´m doing that , but then how i´m supposed to get the reference to the viewmodel ? ;_; if i store it in a variable then it´s gonna overwrite. I´m gonna try using the frame module to get the frame dinamically and then store the page inside it and store it in the viewmodel . It seems odd but i think thats the way to avoid this. Thanks!! c:
– ValdaXD
Nov 17 '18 at 22:35
|
show 1 more comment
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53345723%2fproblem-when-using-the-same-view-in-tabview-along-with-observable%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
Can you create a sample with Playground?
– Manoj
Nov 16 '18 at 21:41
I managed to recreate this on playground play.nativescript.org/?template=play-js&id=zgeCrN , i think that it has something to do with async/await, because when i update the observable statically like "viewModel.set("items", The Page is ' + condition);" , it works as expected.
– ValdaXD
Nov 17 '18 at 15:13
A workaround that i´ve found is to use 2 viewmodels and update them according to the page . it makes the code a little bit messy but i guess it works. However i would like to know what would be the correct approach to avoid this when reusing pages on a tabview.
– ValdaXD
Nov 17 '18 at 15:16
Found another workaround. And is NOT using global variables . play.nativescript.org/?template=play-js&id=zgeCrN&v=2 that works as expected. but it sucks so much that the variable binding is not really binded to their own page , instead is binded to the global .js file. I guess it´s the way Nativescript works "<For each XML file that NativeScript parses, the framework also looks for a JavaScript or TypeScript file with the same name and executes the business logic inside it.>" in docs.nativescript.org/ui/basics.
– ValdaXD
Nov 17 '18 at 15:28