I want to list all my featured news at the top but i can't get them in the right order. This is what i got:
var featuredNewsCollection = allNewsCollection.Where(x =>
featuredNewsIds.Contains(x.Id));
This lists the featured news in the order they appear in allNewsCollection. I want them in the order they appear in featuredNewsIds int list. Is there a smart way to rearrange this?
Try like that:
var featuredNewsCollection = allNewsCollection.Where(x => featuredNewsIds.Contains(x.Id)).OrderBy(x => featuredNewsIds.IndexOf(x.Id));
Related
Sorry if this is really simple...
$('#product-details dd').each((i, el) => {
const title = $(el).text()
console.log(title);
the page im scraping has 12 <dd> tags but i only want the first 7
You can use slice:
$('#product-details dd').get().slice(0,7),map(dd => $(dd).text())
I want to display supplier_address of active user only. Below is the database of the system.
Illustration of my db
Like I mentioned above, I want to display supplier_address of active suppliers only. The image provided above, shows A - supplier_address table and B - status_login table which hold the "active" element.
Right now, my coding look like this,
$activeSupplier = "Active";
// fetch data for 'ACTIVE' Supplier Basic Info Table from table (supplier_profile)
$supplierAddressInfoListTable = SupplierAddress::find()
->select(['supplier_address.supplier_addressID AS supplierAddressID', `
'supplier_address.supplier_profile_ID AS supplierID', 'supplier_address.address_one AS supplierAddressone',`
'supplier_address.address_two AS supplierAddresstwo', 'supplier_address.postcode AS supplierPostcode',
'supplier_address.city AS supplierCity', 'status_login.description AS supplierLoginstatus',
'state.stateID AS supplierStateID', 'state.name AS supplierStatename',
'country.countryID AS supplierCountryID', 'country.name AS supplierCountryname'])
->leftJoin('supplier_profile', 'supplier_profile.supplier_profileID = supplier_address.supplier_profile_ID')
->leftJoin('state', 'state.stateID = supplier_address.state_ID')
->leftJoin('country', 'country.countryID = supplier_address.country_ID')
->where(['=', 'status_login.description', $activeSupplier])
->orderBy(['supplier_profile.supplier_profileID' => SORT_ASC])
->asArray()
->all();
I don't know how I can get by without having to rely on a temporary table. If you guys have some suggestion, please do recommend here.
Also you need to join the login_profile and status_login tables.
`
$activeSupplier = "Active";
// fetch data for 'ACTIVE' Supplier Basic Info Table from table (supplier_profile)
$supplierAddressInfoListTable = SupplierAddress::find()
->select(['supplier_address.supplier_addressID AS supplierAddressID', `
'supplier_address.supplier_profile_ID AS supplierID', 'supplier_address.address_one AS supplierAddressone',`
'supplier_address.address_two AS supplierAddresstwo', 'supplier_address.postcode AS supplierPostcode',
'supplier_address.city AS supplierCity', 'status_login.description AS supplierLoginstatus',
'state.stateID AS supplierStateID', 'state.name AS supplierStatename',
'country.countryID AS supplierCountryID', 'country.name AS supplierCountryname'])
->leftJoin('supplier_profile', 'supplier_profile.supplier_profileID =
supplier_address.supplier_profile_ID')
->leftJoin('login_profile', 'supplier_profile.supplier_profileID =
login_profile.supplier_profile_ID')
->leftJoin('status_login', 'login_profile.status_login_ID =
status_login.status_login_ID')
->leftJoin('state', 'state.stateID = supplier_address.state_ID')
->leftJoin('country', 'country.countryID = supplier_address.country_ID')
->where(['=', 'status_login.description', $activeSupplier])
->orderBy(['supplier_profile.supplier_profileID' => SORT_ASC])
->asArray()
->all()
`
I am trying to add pagination to a page with Html.Pager of the MvcPaging, the problem is that the url generated contains the page number in a value named page.
So I got something like this /orders?page=1
I want it to be like this /orders?pageIndex=1
here is my code
#Html.Pager(Model.PageSize, Model.CurrentPage, Model.TotalPage * Model.PageSize).Options(o => o.DisplayTemplate("_paginationFooter"));
Use the PageRouteValueKey property of Options to override the default value (which is "page")
#Html.Pager(Model.PageSize, Model.CurrentPage, Model.TotalPage * Model.PageSize).Options(o => o
.PageRouteValueKey("pageIndex")
.DisplayTemplate("_paginationFooter")
)
For a complete list of all options (and the source code), refer MvcPaging.
I have this foreach function, but I need to add a where clause.
I have added a checkboxlist in Umbraco called "show"
Values if this is
"EN"
"SP"
"US"
...
Let us say I have checked EN and SP.
I only want a slide to be visible if the slide is Visible as now, and if the field show are "EN" is checked and true. How can i add this in my code?
#foreach (var Slider in Umbraco.ContentSingleAtXPath("//HomePage/SliderArea").Children.Where("Visible").OrderBy("CreateDate
desc").Take(4))
The code you have is using Dynamics and therefore you're restricted to using the pseudo-Linq extensions like .Where("Visible"). You'll find it much easier to manipulate the list of items if you use the Typed objects instead.
Change this:
// Returns IPublishedContent as dynamic
Umbraco.ContentSingleAtXPath("//HomePage/SliderArea")
to this:
// Returns fully typed IPublishedContent
Umbraco.TypedContentSingleAtXPath("//HomePage/SliderArea")
Then you'll be able to use the full power of Linq to do this:
var area = Umbraco.TypedContentSingleAtXPath("//HomePage/SliderArea");
// returns a filtered IEnumerable<IPublishedContent>
var sliders = area.Children.Where(c => c.IsVisible() && c.GetPropertyValue<string>("show") == "EN");
#foreach (IPublishedContent slider in sliders.OrderByDescending(c => c.CreateDate).Take(4))
{
// You can get the dynamic equivalent of the IPublishedContent like this if you wish:
dynamic dSlider = slider.AsDynamic();
// ...
}
I have a menu that is created dynamically with javascript.
First it looks for for section elements with a certain attribute eg:
<section something="add"></section>
And adds them to the menu. It also needs to get the title that will appear on each menu item from each element, eg:
<section something="add" something2="Services"></section>
I don't need any help with the js I just want to know how to add the data to the elements and what names give to the attributes. How should I do it?
it would be easy if we set an ID to section
<section id="sectionUniqueID" data-example="add"></section>
Then manipulate with setAttribute and getAttribute .
// 'Getting' data-attributes using getAttribute
var section = document.getElementById('sectionUniqueID');
var example = section.getAttribute('data-example');
alert(example);
// 'Setting' data-attributes using setAttribute
section.setAttribute('data-example2', 'substract');
var example2 = section.getAttribute('data-example2');
alert(example2);
Working Demo
Reference: http://html5doctor.com/html5-custom-data-attributes/
Here's what I am doing for my dynamic menu items (note: i have no idea what language you're using server side. I use node.js server side and jade for my client side templating).
Note that because you have not asked a precise enough question, I am not exactly sure what you need. You say you want to add data, give us an example of the data you are working with.
Server side:
var user_id = req.session.user.user_id;
// mysql statement to retrieve menu items
mysql.query('select * from menu where user_id = ?',[user_id], function(e, r) {
var menu;
// r would be array of objects:
// [{menu_name: "one", link: "http://foobar.com"},{menu_name:"two",
// link:"http:otherlink.com"}];
if (r.length > 0) menu = r;
else menu = [];
res.render('menu', {menu: menu});
});
Client side:
html
body
section#submenu.navbar
ul#menu
- if (menu.length > 0)
- for (var i = 0; i < menu.length; i++)
li
a(href=#{menu[i].link})= menu[i].menu_name