How to pass an array value to Router.navTo in SAPUI5 - javascript

I have this call in a SAPUI5 code. Before the soldTo was a simple comboBox, but I changed it for a multiComboBox. So, now this.soldTo is an array.
this._oRouter.navTo("SearchResult", {
soldTo: this.soldTo,
shipTo: this.shipTo,
}, false);
The routing in manifest.json is defined like this:
"routing": {
"config": {
"routerClass": "sap.m.routing.Router",
"viewType": "XML",
"async": true,
"viewPath": "com.openOrder.AM.view",
"controlAggregation": "pages",
"controlId": "app",
"clearControlAggregation": false
},
"routes": [
{
"name": "RouteApp",
"pattern": "",
"target": [
"Search"
]
},
{
"pattern": "{soldTo}/{shipTo}/SearchResult",
"name": "SearchResult",
"target": [
"SearchResult"
]
},
{
"name": "ResultDetails",
"pattern": "{}/ResultDetails",
"target": [
"ResultDetails"
]
}
],
"targets": {
"Search": {
"viewType": "XML",
"transition": "slide",
"clearControlAggregation": false,
"viewName": "Search",
"viewLevel": 1
},
"SearchResult": {
"viewType": "XML",
"transition": "slide",
"clearControlAggregation": false,
"viewName": "SearchResult",
"viewLevel": 2
},
"ResultDetails": {
"viewType": "XML",
"transition": "slide",
"clearControlAggregation": false,
"viewName": "ResultDetails",
"viewLevel": 3
}
}
}
I'm getting this error after change.
"Uncaught TypeError: Cannot read properties of null (reading 'length')"
Does anyone has an exemple how to pass the multiComboBox values to the function Router.navTo, please?

There is no need to send the array with a URL. The URL makes only sense if you want a unique address for a specific record. Therefore you should pass it with the model on your component.
Define your model in the manifest. The definition will enable you to access it using "this.getModel(""). In your views you can access the model with "this.getOwnerComponent().getModel("").

Related

kendo UI file manager navigation issue

HTML code:
<div id="filemanager"></div>
javascript code:
$(document).ready(function () {
$("#filemanager").kendoFileManager({
dataSource: {
transport: {
read: function (options) {
$.ajax({
method: "GET",
datatype: "json",
url: Djangourl,
success: function (result) {
console.log(result);
options.success(result);
},
error: function (result) {
options.error(result);
}
});
},
}
}
});
}
JSON returned by server:
[
{
"name": "abc",
"isDirectory": true,
"hasDirectories": true,
"path": "folder",
"extension": "",
"size": 0,
"created": "2022-07-06T11:28:46.932Z",
"createdUtc": "2022-07-06T11:28:46.932Z",
"items": [
{
"name": "abc_123",
"isDirectory": true,
"hasDirectories": true,
"path": "folder/abc_123",
"extension": "",
"size": 0,
"created": "",
"createdUtc": ""
}
],
"modified": null,
"modifiedUtc": null
}
]
Issue: folder 'abc' is displayed but item inside is not getting displayed, on double click on abc again ,ajax is calling the url. I want to display 'abc_123' directory on double click of 'abc' folder as shown in 'https://dojo.telerik.com/UpUgeZOH' example.

Loopback and default sorting

I'm starting to study loopback.
I created my app, and below this model:
{
"name": "movimenti",
"plural": "movimenti",
"base": "PersistedModel",
"idInjection": true,
"options": {
"validateUpsert": true
},
"properties": {
"mov_id": {
"type": "number",
"required": true
},
"mov_tipo": {
"type": "string",
"required": true
},
"mov_valore": {
"type": "number",
"required": true
}
},
"validations": [],
"relations": {},
"acls": [],
"methods": {}
}
I connected the model to my MySQL DB:
"movimenti": {
"dataSource": "banca",
"public": true
}
I launched the application, and went to the address indicated.
I questioned the GET method, having this error:
"stack": "Error: ER_BAD_FIELD_ERROR: Unknown column 'id' in 'field list'\n
but I do not have an ID field in my table.
How can I fix this problem?
Loopback will automatically add an id column if none of the properties of a model is mentioned as id.
Assuming for your model, property mov_id is the id. Define so in the model by adding id: true line: Reference
{
...
"properties": {
"mov_id": {
"type": "number",
"required": true,
"id":true
},
...
}

SAPUI5 root view

I have a problem with rootview. I want create 2 views (login form and home with navigation list).
this is my home view:
I want when I clicked menu in left (root item 1, 2, etc), show content form (just content and still showing menu). I success when root view set to home view but in login view have menu component (navigation list). I want set root view to Home when i load home view, and set root view to other (exclude Home view) when i load login view.
Component.js :
sap.ui.define([
"sap/ui/core/UIComponent"
], function (UIComponent) {
"use strict";
return UIComponent.extend("sap.ui.demo.Component", {
metadata: {
manifest: "json"
},
createContent : function() {
// create root view
var oView = sap.ui.view({
id : "mainContents",
viewName : "sap.ui.demo.template.App",
type : "XML", // <-- change this to JSON
viewData : {
component : this
}
});
// done
return oView;
},
init: function () {
// call the init function of the parent
UIComponent.prototype.init.apply(this, arguments); // calling parent UIComponents
// create the views based on the url/hash
this.getRouter().initialize(); // initializing router
// this.i18nModel(); // set i18n model
},
i18nModel : function(){
var i18nModel = new ResourceModel({
bundleName: "sap.ui.demo.template.i18n.i18n"
});
this.setModel(i18nModel, "i18n");
}
});
});
manifest.json:
{
"_version": "1.1.0",
"sap.app": {
"_version": "1.1.0",
"id": "sap.ui.demo.template",
"type": "application",
"i18n": "i18n/i18n.properties",
"title": "{{appTitle}}",
"description": "{{appDescription}}",
"applicationVersion": {
"version": "1.0.0"
}
},
"sap.ui": {
"_version": "1.1.0",
"technology": "UI5",
"deviceTypes": {
"desktop": true,
"tablet": true,
"phone": true
},
"supportedThemes": [
"sap_hcb",
"sap_bluecrystal",
"sap_belize"
]
},
"sap.ui5": {
"_version": "1.1.0",
"rootView":
{
"viewName": "sap.ui.demo.template.Home",
"type": "XML",
"id": "app"
}
,
"dependencies" : {
"minUI5Version": "1.30",
"libs": {
"sap.ui.core": {},
"sap.m": {},
"sap.tnt": {},
"sap.ui.layout": {}
}
},
"models": {
"i18n": {
"type": "sap.ui.model.resource.ResourceModel",
"settings": {
"bundleName": "sap.ui.demo.template.i18n.i18n"
}
}
},
"routing": {
"config": {
"routerClass": "sap.m.routing.Router",
"controlId": "mainContents",
"viewType": "XML",
"controlAggregation": "pages",
"viewPath": "sap.ui.demo.template",
"async": true
},
"routes": [
{
"pattern": "",
"name": "first",
"target": "first"
},
{
"pattern": "home",
"name": "home",
"target": "second"
},
{
"pattern": "page1",
"name": "page1",
"target": "page1"
},
{
"pattern": "login",
"name": "login",
"target": "login"
},
{
"pattern": "mainContents",
"name": "mainContents",
"target": "mainContents"
}
],
"targets": {
"first": {
"viewName": "Index"
},
"second": {
"viewName": "Home"
},
"page1": {
"viewName": "Page1"
},
"login": {
"viewName": "Index"
},
"mainContents": {
"viewName": "Home"
}
}
}
}
}
I if set root view to Home :
I want to this:
when I set rootview to App, login true but home view false.
App view:
<mvc:View
xmlns="sap.m"
xmlns:mvc="sap.ui.core.mvc"
displayBlock="false">
<App id="mainContents" class="blueBackground">
</App>
</mvc:View>
How to fix this problem about rootview?
Thanks. Bobby.
Set rootview to one view, Handle the rest of the view traversals in controller, with router.navTo() function where you can specify pattern as well.
Just do a cleanup while navigating to another view, destroy the menu created. and create it again on traversal to the concerned view

How to override and rename properties of User built-in model in Loopback Framework

I'm using the loopback framework to create a RESTful API for my application.
Following the documentation, I create my own Customer Model extending the built-in model User.
What I'm trying to achieve is:
How can I rename and remove some properties from this built-in model?
{
"name": "Cliente",
"plural": "Clientes",
"base": "User",
"idInjection": false,
"strict":"true",
...
}
{
"name": "User",
"properties": {
"realm": {
"type": "string"
},
"username": {
"type": "string"
},
"password": {
"type": "string",
"required": true
},
"email": {
"type": "string",
"required": true
},
"emailVerified": "boolean",
"verificationToken": "string"
},
...
}
I reached the results modyfing the loopbacks models inside the node modules, but this solution does not seem the right way, is there a way to config this in my code instead change loopback base models?
I think what you are trying to do is "rename" a property, am I correct?
If so, you can do the following:
"senha": {
"type": "string",
"id": true,
"required": true,
"index": true,
"postgresql": {
"columnName": "password"
}
}
Notice that I have a "postgresql" attribute, which depends on your database connector. Check it here. Inside that attribute I have a "columnName", which is the real name of that column in my database. So "senha" is the new name of that attribute.
For hiding the username property, you could do the following in the root object:
"hidden":["username"]
Your final file should look something like this:
{
"name": "Cliente",
"plural": "Clientes",
"base": "User",
"idInjection": false,
"strict": "true",
"properties": {
"realm": {
"type": "string"
},
"username": {
"type": "string"
},
"senha": {
"type": "string",
"required": true,
"postgresql": {
"columnName": "password"
}
},
"email": {
"type": "string",
"required": true
},
"emailVerified": "boolean",
"verificationToken": "string"
},
"hidden": ["username"]
}

JsTree check nodes

I have saved checked nodes in cookies with this code:
$.cookie('q_cats', $("#category-tree").jstree("get_checked"), { expires: 7 });
I am loading my tree with this code:
$('#category-tree').jstree({
"plugins": ["wholerow", "checkbox", "search"],
"core": {
"themes": {
"responsive": false
},
"data": {
"url": "/blogs/get_cats/",
"dataType": "json"
}
}
});
I don't know how can check saved nodes in my tree
Why don't you use the state plugin - it does exactly that - restore state across refreshes / reloads. Just look it up, all you need to do is add a string to your config (plugins section):
$('#category-tree').jstree({
"plugins": ["wholerow", "checkbox", "search", "state"],
"core": {
"themes": {
"responsive": false
},
"data": {
"url": "/blogs/get_cats/",
"dataType": "json"
}
}
});

Categories