In my SAPUI5 application I have a JS Fragment that does not update my data. If I refresh the window I get the data correctly, but I need to use window.location.reload().
You can check the code below:
onInit: function () {
var oRouters = sap.ui.core.UIComponent.getRouterFor(this);
oRouters.getRoute("chartContainer").attachPatternMatched(this._onObjectMatched, this);
},
_onObjectMatched: function (oEvent) {
var sYear = oEvent.getParameter("arguments").Year;
var sMonth = oEvent.getParameter("arguments").Month;
var sGroup = oEvent.getParameter("arguments").Group;
var sCurrency = oEvent.getParameter("arguments").Currency;
if (sYear === undefined && sMonth === undefined && sGroup === undefined && sCurrency === undefined){
var oStartupParameters = this.getOwnerComponent().getComponentData().startupParameters;
sYear = oStartupParameters.Year;
sMonth = oStartupParameters.Month;
sGroup = oStartupParameters.Group;
sCurrency = oStartupParameters.Currency
}
var sServiceUrl = "/sap/opu/odata/sap/Z_TEST/";
var filterYear = new sap.ui.model.Filter("Year", sap.ui.model.FilterOperator.EQ, sYear);
var filterMonth = new sap.ui.model.Filter("Month", sap.ui.model.FilterOperator.EQ, sMonth);
var filterGroup = new sap.ui.model.Filter("Group", sap.ui.model.FilterOperator.EQ, sGroup);
var filterCurrency = new sap.ui.model.Filter("Currency", sap.ui.model.FilterOperator.EQ, sCurrency);
var oModelOdata = new sap.ui.model.odata.v2.ODataModel(sServiceUrl, {
json: true,
loadMetadataAsync: true
});
var oModel = new sap.ui.model.json.JSONModel();
oModelOdata.read("/DataSet",{
filters: [filterYear, filterMonth, filterGroup, filterCurrency],
success: function(oData, response) {
var oResults = oData.results;
oModel.setData(oData);
var oView = sap.ui.getCore().byId("__xmlview0");
if (oView !== undefined){
oView.setModel(oModel);
}else{
window.location.reload(); // It works correctly butI would like not to have to reload the whole page.
}
}
});
},
How could I refresh the view without refreshing the whole page?
Thanks in advance for your support
Sergio
You should refresh your model by using the refresh() method:
oModelOdata.read("/DataSet",{
filters: [filterYear, filterMonth, filterGroup, filterCurrency],
success: function(oData, response) {
var oResults = oData.results;
oModel.setData(oData);
var oView = sap.ui.getCore().byId("__xmlview0");
if (oView !== undefined){
oView.setModel(oModel);
}else{
oModel.refresh(); // refresh new model data bindings
}
}
});
You should also use promises when making the API call to get the data.
Related
Iam using mxWorkflow -Editor to draw workflow process
then i tried to save the workflow as xml but it is not working
i tried this
function GetXML(container)
{
var graph = new mxGraph(container);
var enc = new mxCodec();
var node = enc.encode(graph.getModel());
var model = graph.getModel();
try
{
// var graph = new mxGraph(container);
graph.model.addListener(mxEvent.CHANGE, function (sender, evt) {
var changes = evt.getProperty('edit').changes;
for (var i = 0; i < changes.length; i++) {
var change = changes[i];
if (change instanceof mxChildChange &&
change.change.previous == null) {
graph.startEditingAtCell(change.child);
break;
}
}
});
}
finally
{
// Updates the display
model.endUpdate();
// graph.getModel().endUpdate();
}
// Adds an option to view the XML of the graph
document.body.appendChild(mxUtils.button('View XML', function()
{
var encoder = new mxCodec();
var node = encoder.encode(graph.getModel());
mxUtils.popup(mxUtils.getXml(node), true);
}));
I've looked at few posts & documentation , but didn't find anything
use function mxUtils.getPrettyXml
var button = mxUtils.button('View XML', function() {
var encoder = new mxCodec();
var node = encoder.encode(graph.getModel());
mxUtils.popup(mxUtils.getPrettyXml(node), true);
});
document.appendChild(button);
I have a search form to call a Solr index, filled with geolocations:
jQuery('.form-submit', element).click(function (e) {
e.preventDefault();
search();
});
function search() {
useBBOX = false;
combinedExtent = ol.extent.createEmpty();
data.map.getLayers().forEach(function (layer, index, array) {
if (layer.getSource() instanceof ol.source.Vector) {
var source = layer.getSource().getSource();
var url = data.opt.urls[source.get('machineName')];
var newSource = new ol.source.Vector({
loader: getLoader(data, url),
format: new ol.format.GeoJSON(),
strategy: ol.loadingstrategy.bbox,
reloadOnZoomChange: true,
reloadOnExtentChange: true
});
newSource.set('machineName', source.get('machineName'));
var newCluster = new ol.source.Cluster({
source: newSource,
distance: 200
});
layer.setSource(newCluster);
}
});
}
function getLoader(data, url) {
return function (extent, resolution, projection) {
var bbox = ol.proj.transformExtent(extent, data.map.getView().getProjection(), 'EPSG:4326');
var params = {};
if (data.opt.paramForwarding) {
var get_params = location.search.substring(location.search.indexOf('?') + 1).split('&');
jQuery.each(get_params, function (i, val) {
if (val.length) {
var param = val.split('=');
params[decodeURIComponent(param[0])] = (param[1] !== undefined) ? decodeURIComponent(param[1].replace(/\+/g, ' ')) : '';
}
})
}
if (useBBOX == true) {
params.bbox = bbox.join(',');
params.zoom = data.map.getView().getZoom();
}
var searchQuery = jQuery('#input-search-address').val();
if (searchQuery != 'undefined' && searchQuery != null) {
url = url.substr(0, url.lastIndexOf("/") + 1);
url = url + searchQuery;
}
jQuery(document).trigger('openlayers.bbox_pre_loading', [{
'url': url,
'params': params,
'data': data
}]);
var that = this;
jQuery.ajax({
url: url,
data: params,
success: function (responsdata) {
var features = that.getFeaturesInExtent(extent);
jQuery(features).each(function (i, f) {
that.removeFeature(f);
});
var format = new ol.format.GeoJSON();
var features = format.readFeatures(responsdata, {featureProjection: projection});
that.addFeatures(features);
that._loadingFeatures = false;
if (!ol.extent.isEmpty(that.getExtent())) {
combinedExtent = ol.extent.extend(combinedExtent, that.getExtent());
if (useBBOX == false) {
useBBOX = true;
}
}
}
});
};
}
Basically, it fetches 3 layers, each containing a number of markers. I'ld like to autozoom the map based on those markers. Therefore I'm looking for the extent. The combinedExtent does contain all correct extents...
... but when I add data.map.getView().fit(combinedExtent, data.map.getSize()) INSIDE the getLoader function, it's not working. I looks like only 1 extent get plotted on the map.
Whenever I try to log the combinedExtent in the search() function, I get a weird error...
Google told me I had to wait until the getState() of newSource was ready, but that didn't work out...
So, I'm looking for a solution. My guess would be the use of the ajax return in getLoader...
I just had this issue, so I have a function to listen until the source is ready and finished loading before giving a count of features (otherwise it would update the log with every iteration). Just change my source name (any variable with "parcelquery in it) with yours and hopefully it will at least put you in the right direction.
var listenerKey = wfsSource_parcelquery.on('change', function(e) {
if (wfsSource_parcelquery.getState() == 'ready') { //says source is done loading
var featureCount = wfsSource_parcelquery.getFeatures().length; //getting number of features resulting from query
ol.Observable.unByKey(listenerKey);
// use vectorSource.unByKey(listenerKey) instead
// if you do use the "master" branch of ol3
}
alert("Your query returned "+ featureCount + " results.");
var extent = lyr_parcelquery.getSource().getExtent();
console.log(extent);
map.getView().fit(extent, map.getSize());
});
i was tested to the IdentyfyTask.
But I could not get a response before the value addCallback.
i want to the pnu values.
But pnu vaule was alwayes undefined...
my code is follows.
function poiClick(){
agmap.addEvent("click", function(evt){
getPoi= krcgis.Function.PoiClick(agmap ,evt);
console.log("X === ",getPoi.x);
console.log("Y === ",getPoi.y);
console.log("PNU === ",getPoi.pnu);
});
}
PoiClick : function(map, evt) {
poiInfo = {};
poiInfo.x =evt.mapPoint.x;
poiInfo.y =evt.mapPoint.y;
var targetLayerId = 'LP_PA_CBND';
var url = map.Layers.getLayerInfo(targetLayerId).SVC_URL;
var map = map.getMap();
//파라미터 설정.
var idParams = new krcgis.core.tasks.IdentifyParameters();
idParams.geometry = evt.mapPoint;
idParams.mapExtent = map.extent;
idParams.returnGeometry = true;
idParams.tolerance = 0;
idParams.layerOption = krcgis.core.tasks.IdentifyParameters.LAYER_OPTION_ALL;
idParams.width = map.width;
idParams.height = map.height;
idTask = new krcgis.core.tasks.IdentyfyTask(url);
idTask
.execute(idParams)
.addCallback(function (response) {
if (response) {
poiInfo.pnu =response[0].value;
}
});
return poiInfo;
}
The results were as follows.
IdentifyTask returns a IdentifyResult object. so you code response[0].value will be undefined.
you should use something like response[0].feature.attributes.PNU
i m calling my save function and st_bookmark and ed_bookmark array donot show any data in my JSON stringfy function the array is undefined or uncaught type error occur
<script>
var check = true;
var st_bookmark = new Array();
var str_print = new Array();
var end_print = new Array();
var ed_bookmark = new Array();
</script>
<script>
function save() {
var link = "M7lc1UVf-VE";
var bk_name = $('#bookmark_name').val();
var bk_tags = $('#bookmark_tags').val();
var bk_email = $('#bookmark_email').val();
var user = '#Session["email"]';
var t = st_bookmark.pop();
var ss = ed_bookmark.pop();
var data =
({ name: bk_name, tags: bk_tags, email: bk_email, link: link, start_bookmark: st_bookmark, end_bookmark: ed_bookmark });
$.ajax({
url: '#Url.Action("save_bookmark", "chopaal")',
type: "POST",
contentType: "application/json",
data: { data: data },
success: function () {
window.alert('success!!');
}
});
var check = true;
var st_bookmark = [];
var str_print = [];
var end_print = [];
var ed_bookmark = [];
}
function starttime() {
if (check == true) {
temp = player.getCurrentTime();
st_bookmark.push(temp);
str_print.push((temp / 60).toFixed(2));
document.getElementById("str_book").innerHTML = str_print;
check = false;
} else {
window.alert("Please End The Previous Bookmark");
}
}
function endtime() {
if (check == false) {
temp = player.getCurrentTime();
ed_bookmark.push(temp);
end_print.push((temp / 60).toFixed(2));
document.getElementById("end_book").innerHTML = end_print;
check = true;
} else {
window.alert("Please Add the Starting Bookmark");
}
}
</script>
Variable declarations are hoisted in JavaScript:
var data = {start_bookmark: st_bookmark};
var st_bookmark = [];
is equivalent to
var data;
var st_bookmark;
data = {start_bookmark: st_bookmark};
st_bookmark = [];
As you can see, st_bookmark is accessed before it got a value assignment, at which point its value is still undefined.
I guess what you really want is to access the variables with the same name that are declared globally. In that case, you should completely remove the declarations of these similarly named variables from save.
If you want to "reset" those variables after the Ajax call was successful, you need to move the assignment inside the success callback and remove the var keyword (so that the identifiers refer to the global variables):
success: function() {
window.alert('success!!');
check = true;
st_bookmark = [];
str_print = [];
end_print = [];
ed_bookmark = [];
}
I have a problem with share parameters from one object to other
I have one LatestVideos object with options my video galleries and other object with methods to Paginate, Render, Categories and LocalStorage, witch handup all functionality but I use this to many this I need this as separete object
(function (window, document, none) {
"use strict";
var LatestVideos = window.LatestVideos = function (option) {
/* object to init puglin data JSON FORMAT keys Jsondata or url , container,
actual page wrapper on paggination, number of item per page, categorywrapper*/
this.fragments = document.createDocumentFragment();
this.categories = ["Favorite"];
this.statusLoad = 0;
this.allid = [];
this.categoryid = [];
this.actual = [];
//this.categoryChecked=[];
this.page = 0;
loadJSON(option.url,this.initData.bind(this));
this.settings = { /// init data from options object from parameter constructor
JsonData :option.data || 0,
container : option.container,
actpage : option.actpage || 1,
buttonwrapper : option.paginationwrapper,
categorywrapper : option.categorywrapper,
itemperpage : option.itemperpage, // get value from prev Selection or default
};
};
LatestVideos.prototype.initData = function (data) { // assinchrounous call json with ajax
this.settings.JsonData = data;
this.settings.lengthData = data.length;
Render.setData(this);
Render.getCategories();
};
var Render = { // need this data from LASTESTVIDEOS data,conteiner,paginationwrapper,categorywrapper
/// object with method to render articles to my website
};
var Pagination = function(){
// from LASTESTVIDEOS I need JsonData, actPage overide page and paginatorwrapper
// object with method to calculate number of pages and paginate my articles
};
var Cateogry = function(){
// from LASTESTVIDEOS categoryid change actual and allid
// object with method to changeCategory and get category from data atribut
};
var LocalStoraget = function (){
// I JSON data from LASTESTVIDEOS
// object with method to getFavorite item form localstorage and add to localstorage
};
})(window, document);
function loadJSON(url, callback) {
/* function to load ajax from url input(url- form and callback function),
output function call and post (ARRAY JSON OBJECTS)*/
var xmlhttp =0;
if (typeof XMLHttpRequest !== 'undefined') {
xmlhttp = new XMLHttpRequest();
} else {
var versions = ["Microsoft.XmlHttp",
"MSXML2.XmlHttp",
"MSXML2.XmlHttp.3.0",
"MSXML2.XmlHttp.4.0",
"MSXML2.XmlHttp.5.0"];
var len = versions.length;
for (var i = 0; i < len; i++) {
try {
xmlhttp = new ActiveXObject(versions[i]);
break;
}
catch(e){}
}
}
xmlhttp.onreadystatechange = ensureReadiness;
function ensureReadiness(){
if (xmlhttp.readyState === 4 && xmlhttp.status === 200)
{
JSONObject = JSON.parse(xmlhttp.responseText);
callback (JSONObject);
}else{
return;
}
}
xmlhttp.open("GET",url,true);
xmlhttp.send();
}
var options = {url:"someURL",container:"videox",paginationwrapper:"pages"};
var opp = new LatestVideos(options);
and this is a plugin witch I need create xtimes with differend options and sometimes I need separetly render or paginate object or localstorage
I would probably change it a bit:
var Render = function (options) {
this.options = $.extend({ //default options
data: [],
container: null
}, options);
// use internal logic here
var getCategories = function(){
...
};
// and return public methods
return {
getCategories: getCategories
};
};
and change the code in LatestVideos to the following:
LatestVideos.prototype.initData = function (data) { // assinchrounous call json with ajax
this.settings.JsonData = data;
this.settings.lengthData = data.length;
var renderer = new Render({
data: this.settings.JsonData,
container: this.settings.container
});
renderer.getCategories();
};