I've used .push() to create "List" input checked array for posting REST API. But it doesn't seem right.
When unchecking, the item in array is not removed automatically. Anybody have a better solution, pls help me! Tks
http://plnkr.co/edit/Y0YggxvVN1epIMWAdtiU?p=preview
You could do this... it works. Can't say this is the best solution though
$scope.$watch('lists', function(lists){
$scope.count = 0;
angular.forEach(lists, function(list){
if(list.checked){
$scope.count += 1;
if (inputsList.indexOf(list.id) == -1) {
inputsList.push(list.id);
};
} else {
inputsList.pop(list.id);
}
})
}, true);
Same logic, but, modified a lil
index.html (added ng-click)
<input type="checkbox" name="list_id[]" ng-model="list.checked" value="{{list.id}}" ng-click='updateItem(list)' />
app.js (removed $scope.$watch and...)
$scope.currentSelectedItem = [];
$scope.updateItem = function(item) {
if(item.checked) {
$scope.currentSelectedItem.push(item);
} else {
$scope.currentSelectedItem.pop(item);
}
}
Related
enter image description hereWhat I'm trying is fetching columns from the user to which the user entered, The Good thing is Columns are getting fetched and the bad thing is the columns that I had applied conditions are not working.Can anyone help me out? I want a query that works for the filter option as in many websites to filter any product or something.
Newbie here!!!
routes.post('/FilterCandidate',function(req,res){
var fetchparameter={};
var dynamicquery={author : req.user.username};
if(req.user.username){
if(req.body.ConsultantName){
fetchparameter["ConsultantName"] = req.body.ConsultantName;
}
if(req.body.Location){
fetchparameter["Location"] = req.body.Location;
}
if(req.body.JobRole){
fetchparameter["JobRole"] = req.body.JobRole;
}
if(req.body.Skills){
fetchparameter["Skills"] = req.body.Skills.split(',');
}
if(req.body.VisaStatus){
fetchparameter["VisaStatus"] = req.body.VisaStatus;
}
if(req.body.BillingRate){
fetchparameter["BillingRate"] = req.body.BillingRate;
}
if(req.body.experience){
fetchparameter["experience"] = req.body.experience;
}
if(req.body.jobtype){
fetchparameter["jobtype"] = req.body.jobtype;
}
if(req.body.Availability){
fetchparameter["Availability"] = req.body.Availability;
}
if(req.body.experience){
fetchparameter["Salary"] = req.body.Salary;
}
if(req.body.Salarytype){
fetchparameter["Salarytype"] = req.body.Salarytype;
}
}
/* This below code for conditions is not working*/
for(var key in fetchparameter){
if (key== "Salary" ){
dynamicquery[key] = {$gte :fetchparameter[key]};
}
if(key == "Skills"){
dynamicquery [key] = {$in : fetchparameter[key]};
}
if(key == "experience"){
dynamicquery[key] = {$gte :fetchparameter[key]};
}
else{
dynamicquery[key] = fetchparameter[key];
}
}
console.log(dynamicquery);
Candidate.aggregate([ {$match : dynamicquery }],(err,docs) =>{
res.render('FilteredCandidate',{'Candidates' : docs});
});
});
This is what I'm getting output to refer to the attached image
i think you should make a match object array it will make your code more neat and hoping that it will solve your problem
Ex:
var match = {$and:[]};
if(any condition satisfy){
match.$and.push({}) //condition
}
and most important do check if match.$and array must not be empty if it is then delete match.$and. this procedure will help you to maintain your query better provides more flexibility.
I'm trying to order the different products from a website but can't do it correctly.
Basically I need to get the price of each one and order them from the most expensive one to the least one.
I tried the following code but it disappears everything and keeps not ordering them in the correct way:
var divList = $(".block-level.h2");
divList.sort(function(a, b){
return $(a).data(".block-level.h2")-$(b).data(".block-level.h2")
});
$(".grid").html(divList);
I don't have access to modify the HTML so it has to be done with the code I have now, only can add things through jQuery.
Can someone give me a tip or help me out please?
Thank you.
For your request to sort the product grid items, here is the jQuery code that you can use.
var values = [];
$('.block-level.h2').each(function() {
var temp = Array();
temp['value'] = parseInt($(this).html().replace('$',''));
temp['element'] = $(this).closest('.grid-item');
values.push(temp);
});
values.sort(function(a,b) { return b.value - a.value; });
var sortedHtml = '';
$.each(values, function(index, obj) {
if((index+1)%3==1) {
sortedHtml+=('<div class="grid product-cards__row"><div class="grid-item one-third palm-one-whole product-cards__item">'+$(obj.element).html()+'</div>');
} else if((index+1)%3==0) {
sortedHtml+=('<div class="grid-item one-third palm-one-whole product-cards__item">'+$(obj.element).html()+'</div></div>');
} else {
sortedHtml+=('<div class="grid-item one-third palm-one-whole product-cards__item">'+$(obj.element).html()+'</div>');
}
});
$('.product-cards').html(sortedHtml);
Hope this helps!
You can achieve this by the following code-
var values = Array();
$('.block-level.h2').each(function() {
values.push(parseInt($(this).html().replace('$','')));
});
values.sort(function(a, b){return b-a});
In your code above - the main problem is with $(a).data(".block-level.h2") since its trying to find an attribute with name data-.block-level.h2 in element a which doesn't exist. That's why the empty result.
i've two tables;
exam_Marks table
{id, codeid, examMarks}
examCodes table
{id, codes, codeDesc}
am trying to fetch the id of codes from table examCodes and pass them to exam_marks table,
however I can't earn this and i don't know where the problem is.
can anyone please help or advice me to use another method
this is my app.js
$scope.examcodesList = function() {
dataFactory.httpRequest(
'dashboard/examcodeList',
'POST',
{},
{"classes":$scope.form.codes}
)
.then(function(data) {
$scope.subje = data.subje;
});
}
and this is my DashboardController.php
public function examcodesList($classes = ""){
$examcodesList = array();
if(!Input::has('classes')){
return $examcodesList;
}
$classes = Input::get('classes');
if(is_array($classes)){
return examcodes::whereIn('id',$classes)->get()->toArray();
}else{
return examcodes::where('id',$classes)->get()->toArray();
}
}
Try with this. Not sure that's what you actually want.
if(is_array($classes)){
return examcodes::join('exam_Marks', 'exam_Marks.codeid', '=', 'examCodes.id')
->whereIn('id',$classes)
->get()->toArray();
}else{
return examcodes::join('exam_Marks', 'exam_Marks.codeid', '=', 'examCodes.id')
->where('id',$classes)
->get()->toArray();
}
I am using https://github.com/localytics/angular-chosen to allow for select tags with search capability for many options.
The problem I'm having is with preselecting an option on an already saved vendor object. When creating a new one there is now issue, but if we're viewing an existing vendor, I want to show the vendor's name in the select box, rather than the placeholder.
<select chosen
ng-model="myVendor"
ng-options="vendor['public-id'] as vendor.name for vendor in vendors"
data-placeholder="Nah">
</select>
And in my controller, I'm setting the model by hand $scope.myVendor = "Some value"
The problem is that I'm populating the options with an object, instead of a key/value. I found an example of it working with a key/value, but haven't had success adapting this to objects as options.
I've even tried setting myVendor to the matching object that I want selected, with no luck.
Plunker of issue
I updated the plunker and change my previous changes on the plugin. this was not the issue. I don't understand how it was giving me errors there.
The solution is to track with an object and two functions the id and the name:
// Controller
$scope.vendors = [
{
"public-id": "1234",
"name": "stugg"
},
{
"public-id": "4321",
"name": "pugg"
}
];
$scope.myVendor = {name: "pugg", id:""};
$scope.updateMyVendorName = function () {
var found = false,
i = 0;
while (!found && i < $scope.vendors.length) {
found = $scope.vendors[i]['public-id'] === $scope.myVendor.id;
if (found) {
$scope.myVendor.name = $scope.vendors[i].name;
}
i++;
}
}
findVendorByName();
function findVendorByName () {
var found = false,
i = 0;
while (!found && i < $scope.vendors.length) {
found = $scope.vendors[i]['name'] === $scope.myVendor.name;
if (found) {
$scope.myVendor.id = $scope.vendors[i]['public-id'];
}
i++;
}
}
// template
<select chosen class="form-control span6" ng-options="vendor['public-id'] as vendor.name for vendor in vendors" ng-model="myVendor.id" ng-change="updateMyVendorName()">
{{myVendor.name}}
I have a complex json string that looks like this:
{
"id":"2016666",
"dt":"2012",
"object_extends":[
{
"extend1":{
"id":"2016666",
"dt":"2012",
"active":"true",
"object_extend":[
{
"extend2":
{
"id":"2016666",
"secondary":null
},
"extend3":
{
"id":"2016666",
"pet":"willy"
}
}
]
}
}
]
}
Now i want to print this like a tree, but when searching for days i have to modify the json(which is not a option). How can i print this in a treeview? I tried for loops but each extend can have other attributes then other objects. Hope somebody can help me with this!
Can you check these out:
How to generate Treeview from JSON data using javascript
https://github.com/lmenezes/json-tree
https://github.com/liuwenchao/aha-tree
https://github.com/AlexLibs/niTree
https://github.com/tamirs9876/JSON.Tree.Builder -- one of my fav
I think visit this and use which you like:
https://github.com/search?utf8=%E2%9C%93&q=json+tree&type=Repositories&ref=searchresults
Edit For Your Request :
To remove the null nodes in https://github.com/tamirs9876/JSON.Tree.Builder -- one of my fav :
Cover line 8 with
if(data[i] != null){
}
in JsonTreeBuilder.js
Last state of js file is like
.
.
var ul = $('<ul>');
for (var i in data) {
var li = $('<li>');
if(data[i] != null){
ul.append(li.text(i).append(generateTree(data[i])));
}
}
.
.