How to render only one document in jade view? - node.js

I need to display only one document from my CouchDB, but if I don't create for-each loop, I can't define variable employer
.row
.col-xs-12.col-sm-8
.row.list-group
each employer in the employers
.col-xs-12.list-group-item
h4
p #{employer.value.name}, #{employer.value.location} #{employer.value.type}, #{employeer.value.position}
small
.col-xs-12.col-sm-4
p.lead= sidebar
When I try to display only one document without the loop, I am receiving an error: Cannot read property 'value' of undefined

If employeers is an array, you should be able to do something like:
employeers[0].value.name
If you want to keep using "employer" you can also replace your each loop with:
- var employer = employeers[0];

Related

Knockout foreach does not display text if already exists

I have an array with different properties. The title property will be duplicated but the other properties in that item will not. I need to display the title property in a table however only if they are not duplicates.
my code below
data-bind="id: 'criteria_category_item_' + Criteria_Category_ID, text: Criteria_Title"
the above will display text for all titles even if they already exist so i now have duplicates in my table.
How would i do this in a foreach ?
there is no data-bind="id
you probably look for attr-binding:
data-bind="attr:{id: ...},text: ..."

How to get object x or y in nested document

I know this has been asked before but I can't seem to find the answer, I want to get data/object in the nested array.
show image problem
schedule = await Schedule.findById({_id:'5b496ec3444152122c8d839e'})
console.log(schedule.datalayout.section.data.x)
If you want to get the specified field in the image, you need to determine field index in the array as down below:
console.log(schedule.datalayout.section[0].data[0].x)
And also, If you want to get all of the x fields in the data array, you need to write something like this:
for(let singleData of schedule.datalayout.section[0].data){
console.log(singleData.x)
}
// for using 'of' keyword, your function must be a async function.

xpages copy field value to another field from other datasource

I followed How do you copy a datetime field from the current document to a new document and I try something like this:
Cdoc.save();
Pdoc.copyItem(Cdoc.getDocument().getFirstItem("mytest1"));
getComponent('exampleDialog').show()
But I get a handling error message.
Thanks for your time!
Assuming Cdoc and Pdoc are defined as xp:dominoDocument data sources then you have to change your code to:
Cdoc.save();
Pdoc.getDocument().copyItem(Cdoc.getDocument().getFirstItem("mytest1"));
getComponent('exampleDialog').show()
So, you only need to add .getDocument() to Pdoc to get the Notes Document. Otherwise it fails and you get the error "Error calling method 'copyItem(lotus.domino.local.Item)' on an object of type 'NotesXspDocument'".
Keep in mind that you have to save Pdoc after copying item too if you want to show the copied item in your exampleDialog.
If you don't want to save document Pdoc at this point yet then you can copy the item on NotesXspDocument level with just:
Pdoc.replaceItemValue("mytest1", Cdoc.getItemValueDateTime("mytest1"));
getComponent('exampleDialog').show()
I do not often use "copyItem". You are not specifying if you are using NotesDocuments or NotesXspDocuments, so I will write a quick thing about both because they should be handled differently.
var currentDoc:NotesDocument = ....
var newDoc:NotesDocument= ...
newDoc.replaceItemValue("fldname", currentDoc.getItemValueDateTimeArray("fldname").elementAt(0))
if currentDoc is a NotesXspDocument, use the following
var currentDoc:NotesXspDocument = ...
var newDoc:NotesDocument=...
newDoc.replaceItemValue("fldname", currentDoc.getItemValueDateTime("fldname"))
Otherwise, you could continue trying with copyItem, I just lack experience with it.
EDIT
Just some things to add, remember that putting calling xspDoc.getDocument(true) will update the background document and this might be needed. Also, in the comments for that article you posted, they mentioned the possible need to put that document into another variable.
var docSource:NotesDocument = xspDoc.getDocument(true);
var docNew:NotesDocument = ...
docNew.copyItem(docSource.getItem("blah");
Also remember that copyItem is a function of NotesDocument and not NotesXspDocument.

Binding an edit box within a custom control to a form field programatically

I have a notes form with a series of fields such as city_1, city_2, city_3 etc.
I have an XPage and on that XPage I have a repeat.
The repeat is based on an array with ten values 1 - 10
var repArray = new Array() ;
for (var i=1;i<=10;i++) {
repArray.push(i) ;
}
return(repArray) ;
Within the repeat I have a custom control which is used to surface the fields city_1 through city_10
The repeat has a custom property docdatasource which is passed in
It also has a string custom property called cityFieldName which is computed using the repeat
collection name so that in the first repeat row it is city_1 and in the second it is city_2 etc..
The editable text field on the custom control is bound using the EL formula
compositeData.docdatasource[compositeData.cityFieldName]
This works fine but each time I add new fields I have to remember to create a new custom property and then a reference to it on the parent page.
I would like to be able to simply compute the data binding such as
compositeData.docdatasource['city_' + indexvar]
where indexvar is a variable representing the current row number.
Is this possible ? I have read that you cannot use '+' in Expression Language.
First: you wouldn't need an array for a counter. Just 10 would do (the number) - repeats 10 times too. But you could build an array of arrays:
var repArray = [];
for (var i=1;i<=10;i++) {
repArray.push(["city","street","zip","country","planet"]) ;
}
return repArray;
then you should be able to use
#{datasource.indexvar[0]}
to bind city,
#{datasource.indexvar[1]}
to bind street. etc.
Carries a little the danger of messing with the sequence of the array, if that's a concern you would need to dig deeper in using an Object here.
compute to javascript and use something like
var viewnam = "#{" + (compositeData.searchVar )+ "}"
return viewnam
make sure this is computed on page load in the custom control
I was never able to do the addition within EL but I have been very successful with simply computing the field names outside the custom control and then passing those values into the custom control.
I can send you some working code if you wish from a presentation I gave.

How to get YUI object on page

I'm using the YUI2 framework.
I want to be able to get a reference to an object that was created on the page. I don't want to change the existing JS code to store a global handle to it when it is created, if possible.
The page has something like this on it:
<script type="text/javascript">//<![CDATA[
new FirstRate.Reporter("report1").setOptions(
{
inData: "testfunc"
}));
//]]></script>
I don't see any methods in YAHOO.util.Dom specific to finding objects.
How can I get an object reference to FirstRate.Reporter? Is there anything to ennumerate the objects on the page?
Thanks
YUI contains lots of methods for finding objects in the webpage DOM. YAHOO.util.DOM contains methods:
HTMLElement | Array get ( el )
Array getElementsBy ( method , tag , root , apply , o , overrides )
HTMLElement getElementBy ( method , tag , root )
Array getElementsByClassName ( className , tag , root , apply , o , overrides )
and many more. These retrieve objects from the DOM. To find an object in the page with YUI2, you would typically use some combination of the tag type, the class name or the id to query the page using YUI methods to find the object you want. It's easiest to find a specific object in the page if you give it a unique id value and then you can just using YAHOO.util.DOM.get("myObject") to retrieve it (where "myObject" is the id of the HTML element).
If you want to get regular javascript objects, then you have to store references to them yourself in your own javascript variables. YUI doesn't do that for you except when using some UI widgets (which also have DOM elements).
If you want to keep track of the result of this:
new FirstRate.Reporter("report1").setOptions(
{
inData: "testfunc"
})
Then, you have to assign it to a variable or to a property of an object whose scope allows it to last long enough for you to use it.
var theReporter = new FirstRate.Reporter("report1").setOptions(
{
inData: "testfunc"
})
or
myObject.reporter = new FirstRate.Reporter("report1").setOptions(
{
inData: "testfunc"
})
where myObject is some other object you've created and are storing.
JavaScript objects aren't part of DOM. DOM is the Document Object Model, it's about objects in HTML document like divs, forms, inputs etc, the kind of objects Browser displays.
There is no "global enumeration" of objects in JavaScript. There are global variables.
I don't want to change the existing JS code to store a global handle to it
So you don't want to use global variable. But why?
This is the only way to do it, and it's also very simple:
var myGlobalVar = new FirstRate.Reporter("report1").setOptions({inData: "testfunc"}));
Here you'll store reference ("handle" as you say) to your object in global var myGlobalVar, which you can later access in another part of your JavaScript code.

Resources