New to angular! So two sets of data. One containing meals, one containing entries. Each meal can have several entries, but each entry only relates to one meal.
In my data, the meals table has an Id, and in the entries table, there is a reference to the meal id with a meal_id property.
meal:
{
id: 4,
user_id: 3,
date: 12345678,
name: "soFood",
location: "Litchfield, CT",
rating: 1,
notes: "This is a note here",
image: "http://www.image.com"
},
entry:
{
id: 3,
meal_id: 4,
name: "Fet UP",
rating: 0,
notes: null,
image: "http://not.anote.here"
}
At the moment I am able to repeat the meals. I'd like to be able to uniquely repeat the entries for an individual meal.
So for a list of meals, be able to click on one and have a list of its unique entries show up.
I know I have to somehow get the meal_id to compare to the id of the meals but I'm unsure how to use ng-repeat doing that?
You will first affect the current meal to a variable in your upper ng-repeat, i.e. ng-repeat="meal in meals". This current meal is known in the scope of the ng-repeat directive. You can use it to filter an entries array and use the result in an inner ng-repeat :
<li ng-repeat="meal in meals">
<div ng-repeat="entry in (entries | filter : {'meal_id': meal.id})">
</div>
</li>
Related
looking around for a solution for my problem!
I try to make Vue.Draggable work with VueFire. I have a few lists with cards that can be dragged between them, sorted, cloned and so on. While the lists are populated with cards Vue.Draggable works perfectly, it watches for changes, triggers events like magic.
This is the working JSON:
categories: [{
name: "todo",
cards: ["second","first","second"]
},{
name: "doing"
cards: ["first","fourth","second"]
},{
name: "done",
cards: ["second", "fourth","first","third"]
}]
The problem comes when one o the lists is empty. We all know that Firebase doesn't store empty properties that's why Vue.Draggable can't watch for a property that doesn't exist. For example like this:
categories: [{
name: "todo",
cards: ["second","first","second"]
},{
name: "doing"
// missing cards property because it's empty
},{
name: "done",
cards: ["second", "fourth","first","third"]
}]
The cards property should be filled with values by dragging items to the list, but because cards doesn't exist Vue.Draggable can't watch for changes in that list and can't trigger events.
Is there a way to create some kind of placeholder or middleware to simulate that empty array? Or what are other possible solutions in this case?
Here's a small JSFiddle.
Thank you!
Why don't you initialize the cards property if nothing is returned from firebase?
categories: [{
name: "todo",
cards: ["second","first","second"]
},{
name: "doing",
cards: firebaseCollectionProperty || []
},{
name: "done",
cards: ["second", "fourth","first","third"]
}]
In Netsuite, the Sales Order record type contains a field called "shipaddresslist" which contains the Customer Address Internal ID associated with the selected Customer Address.
Unfortunately, there is no search column for Sales Orders that will get the value of "shipaddresslist," so I had to find a workaround.
Using SuiteScript, I've been able to get the value of this field by looping through my search results, passing in the Sales Order ID to the record.Load() function, and calling record.getValue() on the loaded record, as shown below
Search:
var salesorderSearchObj = search.create({
type: "salesorder",
filters:
[
["type","anyof","SalesOrd"],
"AND",
["item.isfulfillable","is","T"],
"AND",
["status","anyof","SalesOrd:B","SalesOrd:E","SalesOrd:D"],
"AND",
["quantitycommitted","greaterthanorequalto","1"],
"AND",
["location","anyof","1","3"],
"AND",
["mainline","is","F"],
"AND",
["item.type","anyof","InvtPart"]
],
columns:
[
search.createColumn({
name: "transactionnumber",
sort: search.Sort.ASC,
label: "Transaction Number"
}),
search.createColumn({name: "entity", label: "Name"}),
search.createColumn({
name: "custcol8",
sort: search.Sort.ASC,
label: "JANコード"
}),
search.createColumn({name: "quantityuom", label: "Quantity in Transaction Units"}),
search.createColumn({name: "statusref", label: "Status"}),
search.createColumn({
name: "quantityonhand",
join: "item",
label: "On Hand"
}),
search.createColumn({
name: "isfulfillable",
join: "item",
label: "Can be Fulfilled"
}),
search.createColumn({name: "department", label: "Department"}),
search.createColumn({name: "otherrefnum", label: "PO/Cheque Number"}),
]
});
Loop and Record Loading:
var matches = [];
salesorderSearchObj.run().each(function(result){
var objRecord = record.load({
type: record.Type.SALES_ORDER,
id: result.id,
isDynamic: true,
});
var push = resultToObject(result);
push.addressid = objRecord.getValue({fieldId:'shipaddresslist'});
log.debug("Result:",push);
matches.push(push);
return true;
});
This works great... Except for the fact that I'm returning around 1000 Sales Orders with the search, meaning that the record.Load() eats through my governance units before I can complete the search and build the entire list of results.
In short, is there a way to return the value of "shipaddresslist" from a Sales Order record directly from the search object?
Or perhaps a way to dynamically grab that field without having to load the entire record object?
Any help is greatly appreciated!
SOLVED (KINDA)
Hey all, I asked around and got a semi-solution so in case anyone else comes across this problem, here is a solution.
For my purposes, I was only using SuiteScript because I didn't think you could get the field in Netsuite itself, but I was proved wrong. Here's how to get the field in Netsuite:
Solution
1: Navigate to Lists> Search> Saved Searches> New
2: Select Transaction
3: Under the Criteria tab, Standard subtab, add the following filters:
---Select the Type: Select type of transaction you want to pull up
---Shipping address: Is not empty
---Main Line is True
---Formula (Text):
DECODE({shipaddress}, {customer.address},'1','0')
Starts with 1
4: Under the Results tab add the following columns:
---Shipping Address
---Customer/project fields is Address Internal id
5: Name the search and hit Save & Run.
The only required criteria is the Formula, but this solution is copy and pasted from SuiteAnswers. I recommend just using the Formula and adding in criteria needed as you see fit.
Credit goes to u/seekcant on the r/Netsuite subreddit for finding and posting this solution.
If you are looking for Internal ID of the customer address , you can add this to the search columns
search.createColumn({
name: "internalid",
join: "shippingAddress",
label: "Internal ID"
})
I'm still trying to find my way with AngularJS. I have a JavaScript code that uses URL to return JSON data as an array. I need help with populating the same data in select using ng-options.
data to populate on the select
This isn't how you ask for help, but nevermind. Given a JSON object like this
var JsonArray = [{
id: 1,
name: 'Jane',
address: 'Jane\'s house'
}, {
id: 2,
name: 'Jill',
address: 'Jill\'s house'
}, {
id: 3,
name: 'John',
address: 'John\'s house'
}, {
id: 4,
name: 'Jack',
address: 'Jack\'s house'
}];
When you want to use ng-select with ng-options, you need to specify 3 required fields :
your table
the name that every object will take (like a for ... each loop)
The property you want to see in your options
You also can specify a track by property to give your options a given value.
<select ng-model="mySelect" ng-options="object.name for object in JsonArray track by object.id"></select>
Now, use the last piece of code, and inspect it in a brwoser. You will understand everything.
For reference :
<select ng-model="mySelect" ng-options="[object].[chosenProperty] for [object] in [yourArray] track by [object].[property]"></select>
I have an super big array similar to this:
$scope.providers = [{
providerName: 'John Doe',
colors: 1,
itemQuantity: 100,
item: 'pen',
price: 2,5
},
{
providerName: 'John Doe',
colors: 1,
itemQuantity: 200,
item: 'pen',
price: 2
},
providerName: 'John Doe',
colors: 3,
itemQuantity: 400,
item: 'clock',
price: 10
},
providerName: 'Jane Doe',
colors: 1,
itemQuantity: 50,
item: 'bag',
price: 15
}]
Im building a proposal maker, so I need our business employees to select which provider option they'll be using. (For you to understand these providers just put a logo on our items, and that array of objects is really a list of the prices they charge by quantity of colors, type of item and quantity of items)
The thing is, I want to create a select input with options to first choose which provider we will be using, let's say we settle with John Doe. Then I want a select input to choose the quantity of colors, but will only offer those that John Doe offers. Then I need another input which will let me choose the type of items that John Doe works for that quantity of colors... and so on
Finally I'd like to get the price for all that options
I'm getting quite lost on how to build this on angularjs (version 1.5.8)
Also something tells me I should order my data in a better way than that huge array.
Any suggestion on both issues?
Thanks!
Basically you set it up to have the comboboxes be based off the previous ones (excuse the silly html, it was for demo purposes):
Working Plnkr
<body ng-controller="MainCtrl">
Provider:
<select ng-model="selectedProvider" ng-options="p.providerName as p.providerName for p in providers | unique:'providerName'">{{p}} </select>
<br/>
Selected Provider: {{selectedProvider}}
<br/>
<br/>
Number of Colors:
<select ng-model="selectedNumber" ng-options="n.colors as n.colors for n in providers | filter : {providerName:selectedProvider } | unique:'colors' "> </select>
<br/>
Selected Number: {{selectedNumber}}
<br/>
<br/>
Items:
<select ng-model="selectedItem" ng-options="i.item as i.item for i in providers | unique:'item' | filter : {providerName:selectedProvider, colors: selectedNumber}"> </select>
<br/>
Selected Item: {{selectedItem}}
<br/>
Distinct Prices:
<div ng-repeat="p in providers | filter : {providerName:selectedProvider, colors: selectedNumber, item: selectedItem}">
<span>{{p.price}}</span>
</div>
You'll have to make sure you include 'angular.filter' dependency and the .js file at the top of the plnkr. You may also have to make sure the filtering matches whole words, and not just parts, but this should be more than enough to get you started.
I have the following model:
#order/model.coffee
Order = DS.Model.extend {
line_items: DS.hasMany 'product', {async: true}
}
At some point I want to add the some products to the order. I found that I can only add the product once, adding the same product again does not work:
#product/route.coffee
...
actions:
# Not actually my code but illustrates the problem
addToCart: (product1, product2)->
order = #modelFor 'order'
console.log order.get('line_items.length') # prints 0
order.get('line_items').pushObject product1
console.log order.get('line_items.length') # prints 1
order.get('line_items').pushObject product2
console.log order.get('line_items.length') # prints 2
order.get('line_items').pushObject product1
console.log order.get('line_items.length') # prints 2
order.get('line_items').pushObject product2
console.log order.get('line_items.length') # prints 2
...
The problem is that the user might want a single item more than once. The simplest way to represent that is to have an array with duplicate entries. It seems Ember is not letting me do that for relationships. How can I add a model more than once to a relationship ?
It sounds like you actually need a line_items model with a quantity field. Just shoving more of the same item in your orders model isn't really a normalized solution.
I would recommend the following:
lineItem = DS.Model.extend({
orders: DS.belongsTo('orders'),
product: DS.belongsTo('products'),
quantity: DS.attr('number'),
});
orders = DS.Model.extend({
lineItems: DS.hasMany('lineItem', {async: true}),
customerId: DS.belongsTo('customers'),
});
products = DS.Model.extend({
title: DS.attr('string'),
description: DS.attr('string'),
cost: DS.attr('string'),
});
This would allow you to create multiple records in your lineItem model, that will have a unique ID but be bound to a specific order, (which would solve the issue of multiple orders having the same lineItem) for example, you could have:
{
"lineItem" :
[
{
"id": 1,
"orderId": 1,
"product": 1,
"quantity": 100,
},
{
"id": 2,
"orderId": 1,
"product": 2,
"quantity": 10,
},
{
"id": 3,
"orderId": 2,
"product": 1,
"quantity": 100,
}
]
}
In this design you would remove the reference to lineItems from your json, as ember-data looks after the inverse relationship for you (if you aren't sideloading the relationship you will need to add async to your model). This will mean that if you need to change a line item, it will only affect one order, and if you need to change the order that a lineItem is related to you just do this on the lineItem model.
{
"Orders" :
[
{
"id": 1,
"customerId": 123456,
},
{
"id": 2,
"customerId": 123456,
}
]
}
They should have an id property, then they will be able to co-exist in the same array and be distinct items of the same product type - with the same name (all the same properties other than id).
Either that, or you have one record that represents a product type, and then have a quantity attribute to specify how many of each product there are..