I have an autocomplete textbox function which I am using in meteor.
It works fine for the following hardcoded data like :
$(document).ready(function() {
$("#demo-input-facebook-theme").tokenInput(
[{id: 7, name: "Ruby"},{id: 11, name: "Python"},{id: 13, name: "JavaScript"}],
{theme: "facebook"}
);
});
Now , I had fetched data from database MongoDB, when I pass this data as parameter to the autocomplete function it does not work... I have also used the method JSON.stringify().
The returned data looks like :
[{"_id":"ab170916-a44b-49f9-85ef-a34c90fb815d","Namelist_name":"Badminton"},
{"_id":"f768e4ba-b628-4d3f-8da6-0bad31346dcc","Namelist_name":"Biking"},
{"_id":"0bee086b-1785-40c9-9c5d-a39331c875e1","Namelist_name":"Chess"},
{"_id":"4eae1e54-ec60-4578-8052-0bf1bccf13b1","Namelist_name":"Golf"},
{"_id":"a0d2b89e-a2d6-4b30-8e38-779c5a886d49","Namelist_name":"Hiking"},
{"_id":"f3a05456-38d4-40f2-86b1-eddea061fdf0","Namelist_name":"Tennis"},
{"_id":"3669b9a2-3f87-4579-8064-82d627196fcb","Namelist_name":"Walking"},
{"_id":"6ac6497e-82b2-40fe-8b24-152e9f42750d","Namelist_name":"Wine Tasting"},
{"_id":"15a7ca87-aef7-43ab-945b-168647bb59aa","Namelist_name":"Yoga"},
{"_id":"bc40d166-64ef-4e61-85cd-60064dc037cd","Namelist_name":"Zumba"}]
Just change the Namelist_name with only name keyword. Since jquery tokeninput uses name as key
as mentioned in your hardcoded data. And if we download jquery tokeninput from http://loopj.com/jquery-tokeninput/. we come to know that the keyword is 'name'.
Hope this helps....
If you compare your returned JSON data with the test data that works there is one essential difference: you are missing the id field in your MongoDB JSON results and instead providing _id. The id field is currently a hardcoded default for the jQuery tokenInput plugin you are using for autocomplete.
Several folks have submitted patches to allow setting a different key using the tokenValue parameter.
Example (untested) patch: tokenValue cannot be changed.
If you're autocompleting multiple items with free text, you may want to check out this package I created:
https://github.com/mizzao/meteor-autocomplete
Related
I'm new to SAPUI5 component.
Is there a way to apply $filter to sap.m.Tree? It seems weird to me.
I'm currently using $filter options to limit the data from back-end (by using WHERE clause, came from $filter option), so I have to $filter to pass my parameter.
My controller :
this.oCharTable = this.getView().byId("CharTree")
var aFilterChar = new Filter("Matnr", FilterOperator.EQ , filter_base[2])
this.oCharTable.bindElement({
path: "/AUSP_ENTITY",
model: "AUSP_DATA",
filters: [aFilterChar],
parameters: {
NumberOfExpandedLevels : 2
}
});
and It's $batch payload :
GET AUSP_ENTITY?$filter=HierarchyLevel%20eq%20%270%27&$skip=0&$top=100 HTTP/1.1
sap-cancel-on-close: true
It depends on your data source:
if you have a odata v2, you can't filter on children. This is simply not supported by v2
if you have a odata v4, this is not supported by tree-binding. Good news, it on the roadmap https://github.com/SAP/openui5/issues/2728
if you preload all data an put it in a json model. You could filter as you like with vanilla js
Based on the given answer. You could just ignore v2 specification and filter in the backend as you want with any passed filter.
Oh, I think I found the solution - the problem is on backend!
Thanks to this answer, Using Suspend - Resume makes me send right GET request, like
../AUSP_ENTITY?$filter=HierarchyLevel%20eq%20%270%27%20and%20(Matnr%20eq%20%27SomeKindofMaterialHere%27)&$skip=0&$top=100
I changed my backend to select right values, and returning value to frontend.
For future leaders, who might read my question, I changed my backend to take not only take 1 option (this one, might be Matnr), but also take 'HierarchyLevel', which have to be taken care of.
In detail - I using $filter parameters to get data from CDS View, which can reduce the select result to resonable level.
so I redefine DPC_EXT Class, split up my $filter input, and put it into my parameter, and put result into result table.
TL;dr : If you using $filter on Tree View : check the 'return' backend. It might be problem in there.
I'm trying to change few fields strings using javascript.
For example take only the last part of the URL taken from mongo through the river so in elasticsearch I'll have only the end of it.
When creating the index (using curl) I added under "options" the following script:
"script": "ctx.document.shorturl = ctx.document.url.substr(-4);delete ctx.document.url;
I tried some manipulations such as adding \"...\" or use ctx['doc']['url'] and others but nothing seems to work.
I always get only url field with the full url (shorturl is not created at all).
Can anyone suggest what is the right syntax to make it work?
Another thing I need to do is combine to fields - lat & long, to one "location" field in order to use it in Kibana, can anyone suggest the right script for that? (create new field called "location" which contain both field "lat" & "long" with comma between them).
Thanks.
You did substring(-4), hence it will return the whole string. You should use substring(4) instead:
ctx.document.shorturl = ctx.document.url.substr(4);delete ctx.document.url;
I have issue with key and keys filter parameter in Couchbase (Version: 3.0.0 Enterprise Edition) in the web console. Whatever value I set in those parameters, no record is returned.
Documents look like:
{
"folder": "F3",
"ccy": "USD",
"pnl": 789700,
"maturity": "4424-10-16 00:00 AM CEST",
"source": "BackOffice1",
"npv": 341684,
"symbolic_id": 880888,
"bpv": 374000,
"cpty": "CPTY2"
}
Map function is:
function (doc, meta) {
emit([doc.source,doc.cpty], doc.npv);
}
Reduce is the built in function
_count
I assume that I should be able to get all documents with the key ["BackOffice1","CPTY2"] by setting the key parameter in the querystring ?key=["BackOffice1","CPTY2"]&reduce=true&group=true. But nothing is returned.
I may miss something in how we should use key and keys parameters.
For information, startkey and endkey work as expected.
Is there something wrong with my approach ?
You have to add
keys=["BackOffice1","CPTY2"]
as parameter .
I figured out what was the issue with the key parameter. In the Couchbase version 3.0.0, we need to add inclusive_end=true parameter to get results.
Looking at Couchbase bugs, it looks like it was not required in previous versions and that it will be reverted back in next version, refer to https://www.couchbase.com/issues/browse/MB-12378.
After reviewing samples in Couchbase documentation, my usage of keys parameter was not correct. To query view with array as a key, keys parameter should be formatted as follow:
keys=[["value1",value2"],["value3",value2"]].
If I apply this to the example I provided in my question, the query will look like:
?keys=[["BackOffice1","CPTY2"]] or key=["BackOffice1","CPTY2"]
Thanks
I have the following code:
$("#auto").autocomplete({
source: "js/search.php",
minLength: "3" });
This code is assign to an input text box where i type a name and after 3 letters it should return the ones that have similar letters. For my case it is returning all values, even those not related to the 3 letters already typed. My question is:
How to send my search.php file the value inside the input so it should know what to search for. For the moment it searches for everything. I checked the value that was going to php and it was empty. Since the query to mysql uses LIKE '%VARIABLE%' and the variable is empty it searches for '%%' which is all cases.
How can i send the correct informacion from JS to PHP with the simplest form.
Here is the explanation :
http://www.simonbattersby.com/blog/jquery-ui-autocomplete-with-a-remote-database-and-php/
Regards
Friends,
I'm facing another challenge in APEX and I hope you can help.
I have created a tree using the method described in John & Scott's superb book, "Pro Application Express" whereby the page link is stored in a table. Below is an example:
go to a page passing some parameters
f?p=&APP_ID.:3:&SESSION.::::P3_IDENTIFIER,P3_FAMILY_NAME:&P2_IDENTIFIER.,&P2_FAMILY_NAME.
When the page is run this works as expected. I can expand the tree and navigate to the page passing parameters if required.
However when I turned on session state protection these "hand crafted" links stopped working. Which I expected because the link contains no checksum.
After some investigation I see I have to use APEX_UTIL.PREPARE_URL to generate the URL with a checksum. Unfortunately this is where I run into problems. I can't seem to be able to pass the parameters values to the calling page.
The original tree query was:
select "IDENTIFIER" id,
"PARENT_IDENTIFIER" pid,
"TITLE" name,
"LINK" link,
null a1,
null a2
from <some table>
I then changed this to use APEX_UTIL.PREPARE_URL:
....
APEX_UTIL.PREPARE_URL('f?p='||:APP_ID||':3:'||:APP_SESSION||'::::P3_IDENTIFIER,P3_FAMILY_NAME:&P2_IDENTIFIER.,&P2_FAMILY_NAME.') link,
...
and this works, the page is called and I can see the values of the parameters passed. But I can't use this method as it is restricted to the one page!
Finally I tried storing the page number, parameters and parameter values in different columns of the table that the tree is based on and then bring them together:
...
APEX_UTIL.PREPARE_URL('f?p='||:APP_ID||':'||navigate_to_page||':'||:APP_SESSION||'::::'||parameters||':'||parameter_values) link,
...
Where:
navigate to page has the value of: 3
parameters has the value of: P3_IDENTIFIER,P3_FAMILY_NAME
parameter_values has the values of: &P2_IDENTIFIER.,&P2_FAMILY_NAME.
This now calls the page, but the parameter values have become literals. so where I'm expecting an identifier I see &P2_IDENTIFIER and ditto for family name.
What am I doing wrong? How can I pass values to my called page using apex_util_prepare_url?
In case of need, my environment details are: Apex 3.2.1, Oracle Application Server 10.1.2.3. Oracle Database 10.2.0.3
Thanks in advance for any help you may be able to provide.
I think you'll need to resolve those variables, using the v() function:
APEX_UTIL.PREPARE_URL('f?p='||:APP_ID
||':'||navigate_to_page
||':'||:APP_SESSION
||'::::'||parameters
||':'||v('P2_IDENTIFIER')||','||v('P2_FAMILY_NAME')) link,
On a side note, you might need to be careful about P2_FAMILY_NAME since it's being used in the url; it sounds like a plain text field which contains user-entered data?