i'm working with Meteor js and i'm trying to pass data from a template to another and this is my code :
BuildingsAction.js
Template.BuildingsAction.viewmodel({
showExhibitions() {
FlowRouter.go("/exhibitions");
},})
Actually i would like to pass an _id from BuildingsAction to exhibitions
Template.exhibitions.viewmodel({
onCreated: function () {
this.idItemParent(BuildingsAction_id)// here i whoud like to get the id
})}
There are two ways.
1. Using session.
`Session.set('idVar',YourId);`
Get Session Value:
Session.get('idVar');
2. You can send the id in URL
FlowRouter.go("/exhibitions",{},{id:YourID});
Get queryparam Value:
FlowRouter.getQueryParam("id");
Related
I'm having the following error when trying to access a collection helper from a collection:
TypeError: Cannot read property 'username' of undefined
My helper in /imports/api/.../TaskUser.js :
TaskUser.helpers({
username() {
Meteor.subscribe('users');
elUser = Meteor.users.findOne({_id:this.userId})
return (elUser.username)
}});
My component
renderResponsables(){
return this.props.TaskUsers.map((OneTaskUser) => (
<tr key= {resp._id} onClick={() => this.insert(OneTaskUser._id)}>
<td>{OneTaskUser.username()}</td>
</tr>
));
}
It look like sync problem... but how can I know when it's sync in the client? I usually use subscription.ready() but here with a helper I do not know how to do it.
Advice1:
First add below package
meteor add msavin:mongol
then run the program and press "ctrl+m" it will show you the database tables and your subscribed data.there you can whether that your data has been subscribed or not.
Advice:2
Place your subscribe inside the autorun in oncreated
Template.Dashboard.onCreated(function(){
var self = this;
self.subscribe('users');
});
if above dosn't work then I need to check your users table how you created that and how you retrieve data from there correctly
Did you check this https://guide.meteor.com/react.html#data. You should use react-meteor-data package which provides a function called withTracker. Your subscription should go into it and you have to wrap your component with a container to pass the data.
How to generate multi level path parameters in feathers js like below :
api.com/category/catergoryId/subCatergory/subCatergoryId
The following is taken from this Feathers FAQ entry:
Normally we find that they actually aren't needed and that it is much better to keep your routes as flat as possible. For example something like users/:userId/posts is - although nice to read for humans - actually not as easy to parse and process as the equivalent /posts?userId=<userid> that is already supported by Feathers out of the box. Additionaly, this will also work much better when using Feathers through websocket connections which do not have a concept of routes at all.
However, nested routes for services can still be created by registering an existing service on the nested route and mapping the route parameter to a query parameter like this:
app.use('/posts', postService);
app.use('/users', userService);
// re-export the posts service on the /users/:userId/posts route
app.use('/users/:userId/posts', app.service('posts'));
// A hook that updates `data` with the route parameter
function mapUserIdToData(hook) {
if(hook.data && hook.params.userId) {
hook.data.userId = hook.params.userId;
}
}
// For the new route, map the `:userId` route parameter to the query in a hook
app.service('users/:userId/posts').hooks({
before: {
find(hook) {
hook.params.query.userId = hook.params.userId;
},
create: mapUserIdToData,
update: mapUserIdToData,
patch: mapUserIdToData
}
})
Now going to /users/123/posts will call postService.find({ query: { userId: 123 } }) and return all posts for that user.
Given I have resource id and data as plain JSON, how do I save that JSON to /cars/123/ ???
There seem to be no clear explanation. I don't have restangular element.
restangularizeElement might be the option, but it lacks any meaningful documentation.
All I know is that I want to save {make: 'honda', color: 'now blue, was red'} for car_id == 123.
Thanks.
If you have plain object you cannot use Restangular save function to update (it will make put request as object has id) object.
Easiest way to achieve it construct your end point url then call put function...
Restangular.one('cars', 123).customPUT(carObject).then(function(response){
TO-DO
})
If you want to restangularized your plain object you can use this one...
Restangular.restangularizeElement(null,carObject, 'cars').put().then(function (response) {
TO-DO
})
The comman way should be like this. Whenever you get object from backend with get or getList your object will be Restangularized unless you do not choose to turn them plain object by calling .plain() method of Restangular response. Then you can safely call .save() and it will automatically will be put or post accordingly...
Here is what worked for me. Thanks to #wickY26:
updateGroup: function (group, id_optional) {
if (!group.hasOwnProperty('restangularCollection')) {
// safe to assume it is NOT restangular element; sadly instanceof won't work here
// since there is no element class
// need to restangularize
group = Restangular.restangularizeElement(null, group, ENDPOINT);
group.id = id_optional;
}
return group.put();
},
I'm trying to create a new OpportunityProduct using this rest call:
XRMServices/2011/OrganizationData.svc/OpportunityProductSet
{"ProductId":"ef71ce8e-1ef3-e211-b252-984be17c47e4","Quantity":123,"ProductDescription":"Added from code - TEST123","OpportunityId":"8bdb3525-7274-e311-a90b-6c3be5be5f78"}
The call returns:
The request should be a valid top-level resource object.
This indicates that my arguments is not correct. I see to possible reasons for this:
I'm missing some required properties (How can I figure out which is required?)
It is not possible to do using rest
(both guids are returned via other call and should be correct)
Any help would be great!
Thanks
Larsi
For lookup references to other entities you need to specify both the GUID and the type. You also need to include the UOM when creating an Opportunity Product based on an existing Product. Your object should look something like this:
var entity = {};
entity.Quantity = parseFloat(4).toFixed(2);
entity.OpportunityId = {
Id: '69BB2236-B57F-E311-BB6D-6C3BE5A881A4',
LogicalName: 'opportunity'
};
entity.ProductId = {
Id: 'C8138483-DF81-E311-B542-6C3BE5A8362C',
LogicalName: 'product'
};
entity.UoMId = {
Id: 'BE0FB859-7E90-4B3E-B501-3AB3CD4DC8FC',
LogicalName: 'uom'
};
First of all i am using play framework with scala,
What i have to do is , using the data which i am getting with that function;
onClick: function(node) {
if(!node) return;
alert(node.id);
var id = node.id;
}
So what the question is how i can call the methods from controller with this id ? Since js is client-side but scala works with server-side , i need something creative.
This is the function i need to call from my controller.
def supertrack(id:Long) = Action {
}
I have just found out that i need use ScalaJavaScriptRouting in order to send a ajax request to the server.
For the documentation
http://www.playframework.com/documentation/2.1.1/ScalaJavascriptRouting