Issue refreshing data inside didInsertElement - javascript

I'm having an issue refreshing data inside didInsertElement in a view. I'm calling a model and getting the data (it's being queried from an API) and then loading it into a library (data tables) within didInsertElement. However, once I delete a record the data from the model is outdated and needs to be called again and put into the didInsertElement.
Any help would be greatly appreciated.

If you are manually modifying the dom (or injecting into some third party element) and not using handlebars/ember the observers won't be setup which trigger and update the dom when the underlying model changes. You'll need to set up some observers on the data and manually update the data as you see the data changing.

Related

data persistence across elements

suppose I want to have a data provider element for my user, like
<user-data-provider user-data="{{data}}"></user-data-provider>
which sends an ajax request and gets the logged in user.
Suppose I want to access my user data in different pages, and I add this tag to wherever I need, but the problem is, every time the browser sees this tag, makes an ajax again and I have to wait until data is fetched!
I know I can make a variable in my main page and pass it along child pages, but that seems like overkill to me !
how can I persist user data across different pages and part of my app?
thank you in advance
There are different ways to do this.
You can use use a monostate pattern
You can have one instance of your user-data-provider element in your root element or index.html and use iron-signals to transmit the data to all other elements that want to consume it
You can use iron-meta to have global state
Use an external state management framework (i.e. redux). There is a polymer wrapper for it: polymer-redux
I would recommend using an external state mangement framework such as redux.
Some of the solutions are shown here:
Polymer 1.0 Global Variables
I used pouchdb for my data store, and used polymer's predefined elements to work with it
now every time that I need data, I just use that component

Get edited data of OData Binding

Does anyone know the best approach of getting the changed data of an odata model property after binding it to a form / set of input controls via bindElement?
Currently I am doing something like this.getView().bindElement('/SomeEntitySet(0815)');. But I struggle with getting back the edited data from my view. The only methods the binding is offering to me is getting back the odata model itself, which contains the original, non edited data.
Does anybody know what I'm doing wrong?
In the odataModel there's an Property called refreshAfterChange this should be set to true by default.
Are you sure your changes applies to your backend data? The oDataModel from sapui5 should update the binding by itself(checkout: mParameters.refreshAfterChange).
If the Change method work debug your oData service and check if the change method trigger a GET request to your backend(The odatamodel should trigger a get request if the data has been changed => see refreshAfterChange in link above, the refresh of the model will do a GET request like it does if you bind data to an element). If not theres something wrong with your model confoiguration.
Could you add the code where and how you initiate the model?

When use iron-router, when did onRender is executed?

i am using iron-router and user can router between same templates with different data.
(same route! only route params change)
i need make manipulate on the DOM elements each time that data is changed.
when i put it on onRendered function it's running only at first route!!! or, if i arrive from another route!!!!
how can i force route to rerun the onRendered, or where should i write it to run again automatically when data is changed, AFTER the DOM is complete
I Suggest you to use autorun.
Here is doc: http://docs.meteor.com/#/basic/Tracker-autorun

Write initialization function for directive in angularjs?

I am developing one directive for my grid control, and i need to get some common resource data from server before i build the grid control.
How i can write initialization function for the directive? I need it to execute before loading the control to DOM and it has to be something like lazy one(it should execute only when the DOM got directive).
I have written one function in the controller of directive to get the resource from server, but the directive execution is not waiting for the server response. it is just continuing the execution and throwing resource value is undefined.
Please anyone help to me solve this?
Either you could use the resolve function of your state to have the data loaded before the controller is instantiated at all, see https://docs.angularjs.org/api/ngRoute/provider/$routeProvider
Or you could do it the angular way and
initialize an empty array for your data in the controller
make the ajax request in the controller, and update the array when the response comes in
watch the array to update the dom. If you simply use ng-repeat to show the data, that watch will be set up automatically. If you do "manual" DOM manipulation you must use $scope.$watch() yourself.

Marionette Backbone Composite View update model data on collection changes

I have been using a Marionette Composite View to render to display a page that contains a table of data along with a serious of buttons which allows the user to action on the information.
An example would be a 'reload' button and a 'confirm all' button.
I have encountered a bug whereby repeatedly hitting 'reload' is causing duplicate items in the collection. I'm trying to take this back to basics and understand what is the recommended way of communicating model changes between both the model and the collection in a composite view.
Can someone help?
If you use a Marionette CollectionView or CompositeView they will re-render to reflect what is in your collection, therefore your collection must contain duplicate models.
What are you calling in your refresh method? It sounds like this is where the problem lies. If you want to refresh your collection to reflect what is on the server, you should call the fetch() method on the collection. Default behaviour is to merge the current collection and the data received from the server.
If this is still causing duplicates it could be an error with the data returned from the server - eg if IDs aren't included.
If you want to completely replace the current collection with the data returned from the server you can pass {reset: true} to the fetch call, but this isn't recommended as you will be completely re-rendering every row in the table every time you refresh.

Categories

Resources