I have backend API /search?q=New Je which is return list of JSON cities
"city": "New Jersey"
"city": "New Jenny Lind"
"city": "New Jerusalem"
...
I have a class
final class LocationStore: ObservableObject{
#Published var List : [LocationModel] = []
func search(q: String) {
call backend search API and assign to List
}
}
and I have search TextField in my view.
How to call search api and assign to my list when user type in search TextField. Need to show dropdown after type 3 character in TextField
Loose structure of how you tackle something like this:
Set up a text field that you can observe the output from in some fashion.
If you want to use Combine, create a pipeline that sends the value of that field on every change, and then trigger some output when it matches your spec (>3 characters)
when the combine pipeline triggers, use the value provided, or just the nature of the trigger, to do whatever action you have in mind.
There's sample code that does nearly exactly this available online within Using Combine in the pattern named Declarative UI updates from user input. It covers a bit more. The github project that hosts Using Combine has a SwiftUI variation of this as well in the project if you'd prefer to see it with SwiftUI.
Related
I wanted to use javascript addin's to get the style object and get some proerties of it for example maybe paragraph property and get the indentation of this specific style but I cant get to the style object and get the property of it. I know that there is a collection of every style in document but I cant get any properties of those. There is way to change style in selected range but it could be very fine if I could get style from the range maybe and like i said erlier get some properties of it.
This is code in Word VBA that is example of property i want to see value of:
documents("[file_name]").Styles([index]).ParagraphFormat.LeftIndent
We can set the value to any variable:
Dim var As Integer/Long
Let var = documents("[file_name]").Styles([index]).ParagraphFormat.LeftIndent
As far as I know the office.js API for Word does not currently (v. 1.4) provide any Style objects with the kind of properties that you are used to seeing via the Object Model that VBA uses. All it lets you do is get the style names (localized and built-in) associated with another object such as a range, a paragraph, or various style properties associated with a table.
i.e. at the moment, the only way you would be able to get detailed style information would probably be to retrieve the document's XML and interpret that. Hard, I suspect.
I think that probably answers your question but in case you were looking for code to retrieve a style, to get the style name of a range, say, is straightforward, e.g. in Script Lab you can start with one of the basic JavaScript samples and modify its run function so it looks like this:
function run() {
return Word.run(function(context) {
var range = context.document.getSelection();
range.load("style");
return context.sync().then(function() {
console.log('The selected style was "' + range.style + '".');
});
});
}
Precisely which style name you get depends on the range - if you select two paragraphs with different styles, the style name will be "", and so on.
Basically what I am trying to accomplish is to have a table which has a section for each Division and within that section have subsections for each Company within that Division. This is as close as I have gotten (with DivisionTable and CompanyTable both being repeating content controls):
After populating the template from a workflow the Divisions are working fine (its repeating three times w/ the correct info) but in the Company Table it just shows [obj] where it should be the Company Name. It also looks like there may be two new unnamed tags placed here after its generated but I'm not sure.
In the Populate a Word Template action inside the DivsionTable tag I am putting an array:
This is what the first object in the array looks like:
{
"CompanyTable": [
{
"CompanyName": "Company Name Goes Here"
}
],
"DivisionDesc": "Finishes",
"DivisionNo": "09"
}
Is what I am trying to do even possible? I looked at some other posts but I never saw a clear answer.
If it is possible then what exactly am I doing wrong? If it is not possible do you have any suggestions on how to accomplish this another way?
I'm working on an application that reuses a lot of constants. I know that I can use wire IDs to use the same data in multiple places, but I'm not sure if I'm supposed to create a new globally unique ID every time I want to use that data.
This is a simplified example of what I'm working with:
const colors = [
{value: 'red', label: 'Red'},
{value: 'blue', label: 'Blue'}
]
class MyElement extends HTMLElement {
constructor() {
super()
this.html = hyperHTML.bind(this)
}
connectedCallback() {
this.html`
Hi, ${this.getAttribute('name')}! What is your favorite color?<br/>
<select>
${colors.map(option => hyperHTML.wire(option)`<option value=${option.value}>${option.label}</option>`)}
</select>
`
}
get name() {
return this.getAttribute('name')
}
}
customElements.define('my-element',MyElement);
hyperHTML.bind(document.body)`
<my-element name="Alice"></my-element>
<my-element name="Bob"></my-element>`
I know that unless I specify a wire ID, the options will only appear in one place. I could use :${this.name} as the wire ID, but I have to figure out what to do if there are two people with the same name, and if I want to have one form for "What is your favorite color?" and another for "What color is your shirt?", I have to make another unique ID for that.
Is there a way to somehow scope wire IDs or do I have to make globally unique ones?
There is a subtle issue in your logic, you'd like to map an array of items to themselves, instead of contextualizing their value.
Example: you are wiring the option object, out of usage, situation, context, instead of wiring the Custom Element instance to some data it's using to render itself.
As you can see in this CodePen example, you can simply wire the Custom Element context, and make the option information unique, in terms of scoped id, simply pointing at its value, through its owner:
hyperHTML.wire(this, `:option:${option.value}`)
At this point you'll have a single option element per each node so that you can easily select anything you want instead of moving the same option node globally all over the place.
Actually, the global ID is an anti-pattern as it is, I believe, in every other keyed framework such React or Vue so ... just use the instance, as your wire context/reference, and create a unique id for it with ease.
I hope this solved your issue.
I hope you can help me with this. After reading all the documentation several times, googling for days, etc I don't find the way to do what i'm going to explain in a clean way, and in think I'm missing something because it's a really basic scenario.
I'm working with oData models, in this case 2 named models, "Model1", "Model2". Now what I want is to show a "parent" ComboBox based on an oData path, and a table that changes its items depending on the selection, in other words.
Model1 { //JSON representation of the data.
Accounts:[
"account 1": {invoices: ["invoice1", "invoice2", "invoice3"]},
"account 2": {invoices:["invoice4", "invoice5"]}
]
}
Combo Box:
<... items={Model1>/Accounts} /> -- This works and shows Account 1, and Account2.
Table
<Table... items="{Model1>Invoices}">
..
<items>
....
</items>
</Table>
What I want is the table to change it's context to the account selected on the ComboBox. The point is that this works, but the first time it loads the view, as there is no account selected, it calls the wrong odata path MYSERVICE/Invoices, instead of doing nothing, as the Account is not set yet, and the path for the invoices, once selected the account, shoud be MYSERVICE/Account('Account1')/Invoices for example.
I know I can achieve this with code, but I'm sure there must be a clean way to do this.
Seriously, this is driving me crazy.
Thanks for your help.
Are you sure that
items="{Model1>Invoices}"
triggers odata call? Because this is a relative path (without leading slash), normally it should not do the call.
What you can do:
Handle ComboBox selectionChange event;
In this event handler, create a path that you will bound the table to. In your case the path could look like this: "/Account(Account1)" - "/{EntitySetName}({KEY})". You can make use of createKey method of ODataModel2;
Set the table's context using the path:
oTable.bindObject({
path: sPath,
model: "Model1",
parameters: {
$expand: "Invoices"
}
});
Once the context is set, the relative binding will start working automatically and table will get the "Invoices"
I assume that the Account and Invoices are linked via navigation property and one-to-many cardinality, that's why the $expand parameter will load the corresponding invoices.
This is the List Report type of Smart Template application
Here I have selected 2nd and 5th row, I also have a button named Send Requests in the section part which is highlighted. If I click this button it calls a javascript controller function which is defined in the extensions of the application. In this js function how can I retrieve the selected rows that are selected?
I have enabled the checkboxes in this page by mentioning this code
"settings": { "gridTable": false, "multiSelect": true } in the manifest.json
As it was recommended by this link https://sapui5.netweaver.ondemand.com/#docs/guide/116b5d82e8c545e2a56e1b51b8b0a9bd.html
I want to know how can I retrieve the rows which got selected?
There is an API that you can use for your use case. It is described here: https://sapui5.netweaver.ondemand.com/#docs/guide/bd2994b69ef542998becbc69ab093f7e.html
Basically, you just need to call the getSelectedContexts method. Unfortunately you will not be able to really get the items themselves, only the binding contexts (which point to the data entities which are selected). Excerpt from the documentation:
After you have defined a view extension, you can access and modify the
properties of all UI elements defined within these extensions (for
example, change the visibility). However, you cannot access any UI
elements that are not defined within your view extensions.
In this type of table there is way.
var myTable=sap.ui.getCore().byId("your table id");
get all rows:
var myTableRows=myTable.getRows();
now get selected Indices
var selectedIndeices=myTable.getSelectedIndices(); //this will give you array of indeices.
now run loop on indeices array. And get particular row item;
// get binding path
var bindingpath=myTableRows[2].getBindingContext().sPath; // this will return eg:"/ProductCollection/2"
// now get Binding object of that particular row.
var myData=myTableRows[2].getModel().getObject(bindingpath); // this will return binding object at that perticular row.
// once your loop is over in the end you will have all object of selected row. then do whatever you want to do.
If you use smart template create an extension.
This is the standard event befor the table is rebinding:
onBeforeRebindTableExtension: function (oEvent) {
this._table = oEvent.getSource().getTable();
}
In your action function (or where you want) call the table and get the context :
this._table.getSelectedContexts();