Unsolved Remove and update model in listView
-
I have a 7 day listView, and in each of these 7 days I have rectangles in a repeater taken from the same model of the days, declared in the attributes field.
When I click on a listView a new page opens with the detail of the rectangles arranged individually and each of these rectangles can be removed (except the first one) or added new ones.
Now I'm taking care of the removal part, and when I click on the X that period is removed from the model.
The problem that in addition to updating the single view when I close the aforementioned page, the one from which I came must also update, and in a certain sense it does, but not as I would like.
The model seems correct, but among the things that need to be updated there is also the size of the rectangles that when I remove a period must change.
This is the code I call when I click on the remove button and it has strange behavior. It removes the period, and the model also seems to update, but when I close the period the main page shows the data in a somewhat strange way.
function removePeriod(indexWeekday, weekday, index) { var modelData = model.get(indexWeekday); var newWidth = ((decode_time(modelData.attributes.get(index).myStop) - decode_time(modelData.attributes.get(index - 1).myStart)) / 24)* window.width - 30; var newStop = modelData.attributes.get(index).myStop; modelData.attributes.set(index - 1, {myWidth: newWidth}); modelData.attributes.set(index - 1, {myStop: newStop}); modelData.attributes.remove(index); var day = []; for (var i = 0; i < modelData.attributes.count; i++) { day.push(modelData.attributes.get(i)); } model.set(indexWeekday, {"weekday": weekday, "attributes": day}) console.log(JSON.stringify(modelData)); scheduleSinglePeriod.remove(index); }
I give an example of what needs to be done:
Let's take into account that I have a rectangle divided into 3 periods which total is 800 (the masisma width of the window, since it must be displayed on a touch screen of that size).
The rectangles are composed as follows:
First period the width will be 283.33, with the starting time of 0:00 and the end of 8:30.
Second period 450 and runs from 8:30 to 22:00
Third period goes 66.66 and runs from 22:00 to 24:00
Let's assume that I delete the last period must become like this:
First period does not change, but the second period must become 450 + 66.66 and the end of the period will become the end of the one just canceled, therefore no longer 22:00 but 24:00.
The problem that when I go back to the main page the periods I see them all a little busted.
Thank you
-
marco_88 less than a minute ago
I resolved replaced model.set with these 2 lines:
model.insert(indexWeekday, {"weekday": weekday, "attributes": day})
model.remove(indexWeekday + 1)I don't know if this code is clear and if it is a good way for update model.
I insert day row correctly on correct index sometimes I remove a period, and after remove next index, that is old day duplicated.
Thanks