why watch cannot work after edit an object?
I have an array in Vuejs.
overtime_rates: ;
This array comes from the parent to this page. I sent it through v-model="overtime.overtime_rates" , and take it in the child as:
props:
value: Array,
,
computed:
overtime_rates:
get()
return this.value;
,
set(value)
this.$emit('input', value);
,
,
In my method when the array is empty (in create mode) and i try to push the object into it, the watch works fine and can capture all changes for any new push.
let rateOT =
startTime:
hours: 0,
minutes: 0,
,
endTime:
hours: 23,
minutes: 59,
,
this.overtime_rates.push(rateOT);
But after i save the array in database and fetch it for edit, when i try to edit each record the watch cannot catch the changes.
The function which is called in watch is :
method:
autoTime()
for (let i = 1; i < this.overtime_rates.length; i++)
if (this.overtime_rates[i - 1].endTime.minutes >= 0
&& this.overtime_rates[i - 1].endTime.minutes < 59)
this.overtime_rates[i].startTime.minutes =
parseInt(this.overtime_rates[i - 1].endTime.minutes) + 1;
this.overtime_rates[i].startTime.hours =
parseInt(this.overtime_rates[i -
1].endTime.hours);
else if (this.overtime_rates[i - 1].endTime.minutes == 59)
this.overtime_rates[i].startTime.minutes = 0;
this.overtime_rates[i].startTime.hours = parseInt(this.overtime_rates[i - 1].endTime.hours) + 1;
,
The watch code is as follow:
watch: {
value:
handler: function ()
this.autoTime();
,
deep: true
,
Pleas any one can help me?
javascript vue.js
|
show 1 more comment
I have an array in Vuejs.
overtime_rates: ;
This array comes from the parent to this page. I sent it through v-model="overtime.overtime_rates" , and take it in the child as:
props:
value: Array,
,
computed:
overtime_rates:
get()
return this.value;
,
set(value)
this.$emit('input', value);
,
,
In my method when the array is empty (in create mode) and i try to push the object into it, the watch works fine and can capture all changes for any new push.
let rateOT =
startTime:
hours: 0,
minutes: 0,
,
endTime:
hours: 23,
minutes: 59,
,
this.overtime_rates.push(rateOT);
But after i save the array in database and fetch it for edit, when i try to edit each record the watch cannot catch the changes.
The function which is called in watch is :
method:
autoTime()
for (let i = 1; i < this.overtime_rates.length; i++)
if (this.overtime_rates[i - 1].endTime.minutes >= 0
&& this.overtime_rates[i - 1].endTime.minutes < 59)
this.overtime_rates[i].startTime.minutes =
parseInt(this.overtime_rates[i - 1].endTime.minutes) + 1;
this.overtime_rates[i].startTime.hours =
parseInt(this.overtime_rates[i -
1].endTime.hours);
else if (this.overtime_rates[i - 1].endTime.minutes == 59)
this.overtime_rates[i].startTime.minutes = 0;
this.overtime_rates[i].startTime.hours = parseInt(this.overtime_rates[i - 1].endTime.hours) + 1;
,
The watch code is as follow:
watch: {
value:
handler: function ()
this.autoTime();
,
deep: true
,
Pleas any one can help me?
javascript vue.js
you have to re-watch it after db fetch as it is a new instance and watch was for the previous instance
– Nikos M.
Nov 15 '18 at 9:29
@NikosM. thank you so much , may i ask you how can i do rewatch? I edited and added my watch code in the question.
– Sara
Nov 15 '18 at 9:53
hmm i'm afraid I cannot get how you watch the object it is not clear from the code you posted, do you use a polyfill? where exactly does this code reside? what isthis.autoTime()
? these are missing, I can help better if I know that
– Nikos M.
Nov 15 '18 at 9:58
Thanks @NikosM. i just afraid that if i put whole code it becomes confusing , i edited again and include the additional code
– Sara
Nov 16 '18 at 1:19
Ok I see now, but I think you should post thr code that fetches the array back from db for editing.
– Nikos M.
Nov 16 '18 at 9:27
|
show 1 more comment
I have an array in Vuejs.
overtime_rates: ;
This array comes from the parent to this page. I sent it through v-model="overtime.overtime_rates" , and take it in the child as:
props:
value: Array,
,
computed:
overtime_rates:
get()
return this.value;
,
set(value)
this.$emit('input', value);
,
,
In my method when the array is empty (in create mode) and i try to push the object into it, the watch works fine and can capture all changes for any new push.
let rateOT =
startTime:
hours: 0,
minutes: 0,
,
endTime:
hours: 23,
minutes: 59,
,
this.overtime_rates.push(rateOT);
But after i save the array in database and fetch it for edit, when i try to edit each record the watch cannot catch the changes.
The function which is called in watch is :
method:
autoTime()
for (let i = 1; i < this.overtime_rates.length; i++)
if (this.overtime_rates[i - 1].endTime.minutes >= 0
&& this.overtime_rates[i - 1].endTime.minutes < 59)
this.overtime_rates[i].startTime.minutes =
parseInt(this.overtime_rates[i - 1].endTime.minutes) + 1;
this.overtime_rates[i].startTime.hours =
parseInt(this.overtime_rates[i -
1].endTime.hours);
else if (this.overtime_rates[i - 1].endTime.minutes == 59)
this.overtime_rates[i].startTime.minutes = 0;
this.overtime_rates[i].startTime.hours = parseInt(this.overtime_rates[i - 1].endTime.hours) + 1;
,
The watch code is as follow:
watch: {
value:
handler: function ()
this.autoTime();
,
deep: true
,
Pleas any one can help me?
javascript vue.js
I have an array in Vuejs.
overtime_rates: ;
This array comes from the parent to this page. I sent it through v-model="overtime.overtime_rates" , and take it in the child as:
props:
value: Array,
,
computed:
overtime_rates:
get()
return this.value;
,
set(value)
this.$emit('input', value);
,
,
In my method when the array is empty (in create mode) and i try to push the object into it, the watch works fine and can capture all changes for any new push.
let rateOT =
startTime:
hours: 0,
minutes: 0,
,
endTime:
hours: 23,
minutes: 59,
,
this.overtime_rates.push(rateOT);
But after i save the array in database and fetch it for edit, when i try to edit each record the watch cannot catch the changes.
The function which is called in watch is :
method:
autoTime()
for (let i = 1; i < this.overtime_rates.length; i++)
if (this.overtime_rates[i - 1].endTime.minutes >= 0
&& this.overtime_rates[i - 1].endTime.minutes < 59)
this.overtime_rates[i].startTime.minutes =
parseInt(this.overtime_rates[i - 1].endTime.minutes) + 1;
this.overtime_rates[i].startTime.hours =
parseInt(this.overtime_rates[i -
1].endTime.hours);
else if (this.overtime_rates[i - 1].endTime.minutes == 59)
this.overtime_rates[i].startTime.minutes = 0;
this.overtime_rates[i].startTime.hours = parseInt(this.overtime_rates[i - 1].endTime.hours) + 1;
,
The watch code is as follow:
watch: {
value:
handler: function ()
this.autoTime();
,
deep: true
,
Pleas any one can help me?
javascript vue.js
javascript vue.js
edited Nov 16 '18 at 1:27
Sara
asked Nov 15 '18 at 9:20
SaraSara
14
14
you have to re-watch it after db fetch as it is a new instance and watch was for the previous instance
– Nikos M.
Nov 15 '18 at 9:29
@NikosM. thank you so much , may i ask you how can i do rewatch? I edited and added my watch code in the question.
– Sara
Nov 15 '18 at 9:53
hmm i'm afraid I cannot get how you watch the object it is not clear from the code you posted, do you use a polyfill? where exactly does this code reside? what isthis.autoTime()
? these are missing, I can help better if I know that
– Nikos M.
Nov 15 '18 at 9:58
Thanks @NikosM. i just afraid that if i put whole code it becomes confusing , i edited again and include the additional code
– Sara
Nov 16 '18 at 1:19
Ok I see now, but I think you should post thr code that fetches the array back from db for editing.
– Nikos M.
Nov 16 '18 at 9:27
|
show 1 more comment
you have to re-watch it after db fetch as it is a new instance and watch was for the previous instance
– Nikos M.
Nov 15 '18 at 9:29
@NikosM. thank you so much , may i ask you how can i do rewatch? I edited and added my watch code in the question.
– Sara
Nov 15 '18 at 9:53
hmm i'm afraid I cannot get how you watch the object it is not clear from the code you posted, do you use a polyfill? where exactly does this code reside? what isthis.autoTime()
? these are missing, I can help better if I know that
– Nikos M.
Nov 15 '18 at 9:58
Thanks @NikosM. i just afraid that if i put whole code it becomes confusing , i edited again and include the additional code
– Sara
Nov 16 '18 at 1:19
Ok I see now, but I think you should post thr code that fetches the array back from db for editing.
– Nikos M.
Nov 16 '18 at 9:27
you have to re-watch it after db fetch as it is a new instance and watch was for the previous instance
– Nikos M.
Nov 15 '18 at 9:29
you have to re-watch it after db fetch as it is a new instance and watch was for the previous instance
– Nikos M.
Nov 15 '18 at 9:29
@NikosM. thank you so much , may i ask you how can i do rewatch? I edited and added my watch code in the question.
– Sara
Nov 15 '18 at 9:53
@NikosM. thank you so much , may i ask you how can i do rewatch? I edited and added my watch code in the question.
– Sara
Nov 15 '18 at 9:53
hmm i'm afraid I cannot get how you watch the object it is not clear from the code you posted, do you use a polyfill? where exactly does this code reside? what is
this.autoTime()
? these are missing, I can help better if I know that– Nikos M.
Nov 15 '18 at 9:58
hmm i'm afraid I cannot get how you watch the object it is not clear from the code you posted, do you use a polyfill? where exactly does this code reside? what is
this.autoTime()
? these are missing, I can help better if I know that– Nikos M.
Nov 15 '18 at 9:58
Thanks @NikosM. i just afraid that if i put whole code it becomes confusing , i edited again and include the additional code
– Sara
Nov 16 '18 at 1:19
Thanks @NikosM. i just afraid that if i put whole code it becomes confusing , i edited again and include the additional code
– Sara
Nov 16 '18 at 1:19
Ok I see now, but I think you should post thr code that fetches the array back from db for editing.
– Nikos M.
Nov 16 '18 at 9:27
Ok I see now, but I think you should post thr code that fetches the array back from db for editing.
– Nikos M.
Nov 16 '18 at 9:27
|
show 1 more comment
0
active
oldest
votes
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%2f53316060%2fwhy-watch-cannot-work-after-edit-an-object%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
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%2f53316060%2fwhy-watch-cannot-work-after-edit-an-object%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
you have to re-watch it after db fetch as it is a new instance and watch was for the previous instance
– Nikos M.
Nov 15 '18 at 9:29
@NikosM. thank you so much , may i ask you how can i do rewatch? I edited and added my watch code in the question.
– Sara
Nov 15 '18 at 9:53
hmm i'm afraid I cannot get how you watch the object it is not clear from the code you posted, do you use a polyfill? where exactly does this code reside? what is
this.autoTime()
? these are missing, I can help better if I know that– Nikos M.
Nov 15 '18 at 9:58
Thanks @NikosM. i just afraid that if i put whole code it becomes confusing , i edited again and include the additional code
– Sara
Nov 16 '18 at 1:19
Ok I see now, but I think you should post thr code that fetches the array back from db for editing.
– Nikos M.
Nov 16 '18 at 9:27