Sencha Fiddle
My API returns JSON object visible in Attachments.store.Attachments data. It seems to me that the structure consists of 4 models: AttachmentObject, AttachmentDef, AttachmentFile and AttachmentNote. I've defined them in the fiddle and associated each other using hasOne and hasMany. I've also created a simple grid and a form.
In the grid I want to present attachment's name in the last column, but I can't access child nodes using dataIndex property. When passing only "attachmentDef" as dataIndex grid converts child to "[object Object]" string, which means the nested data is noticable by the grid. I've also tried to retrieve the name using renderer, but then sorting functionality is gone.
API expects same JSON format in case of posting a new attachment. How to instantiate above models and bind chosen model fields (i.e. name and note) with form fields?
here's the fiddle with child nodes and sort: https://fiddle.sencha.com/#view/editor&fiddle/257b
I've changed the store load and I've used 'templatecolumn' and 'widgetcolumn' to show data.
the creation of a new attachment depends on how you'd like to make it work, I suppose you might want to call a specific ws (defined in attachment model) to create a new attachment and then reload the grid's store
Related
I am using angular js datatable for my project. Currently I am trying to access below object,
"finalizedArr":[
{
"treaceId":"KYC454353545",
"approval":[
{
"usr":"kalindu kumara",
"threshold":100
},
{
"usr":"kuma kalil",
"threshold":80
},
]}
]
I am using below code sample to generate table. This is the main part code
$scope.dtColumns = [
DTColumnBuilder.newColumn('traceId').withTitle('Trace ID'),
DTColumnBuilder.newColumn('approval.usr').withTitle('Name'),
DTColumnBuilder.newColumn('approval.threshold').withTitle('Match Strength %')
];
When I use this code, treaceId column is correctly rendered in the table. but 'usr' and 'threshold' not rendered. I think reason is ,usr and threshold inside the array. but i do not know how to modify this. Can you check my issue
Out-of-the-box ngTable dynamic expects column.field to be property names, not navigators. (i.e. it doesn't handle dot syntax oneProperty.anotherProperty as it effectively does columnObject["fieldNameYouProvided"])
You could try a similar solution as noted here or you could try mapping your data model to a flat object.
Lastly, approval.usr and approval.threshold are not valid property accessors for the provided data model because approval is an array so to access the first values you would access them with approval[0].usr and approval[0].threshold which will not work as a dynamic column field property value for the aformentioned reasons.
I'm trying to modify the stocklist Dynagrid demo which is designed to work with HTML5 and Javascript, it's originally designed to subscribe an item per subscription.
In my case, I have connected this demo to my lightstreamer server, the adapter in my server deals with itemgroub and fieldschema instead of itemList and fieldList which was used in the example.
I modified the code to subscribe using this item group and equivalent field schema, now the dynagrid listener (onVisualUpdate function) is capable to detect how many items in the item group and based on that it creates the equivalent number of rows, however, when I call getChangedFieldValue for and one of the fields in the dynagrid, I get null always, and based of that no data is updated on the screen.
What is the solution for this problem, and how can I get the updated values?
(Note: Currently, I get the data directly from the info paramter which is passed to onVisualUpdate function).
When using a Field Schema, fields in the subscription are identified by their 1-based index within the schema and not by their name. So, wen you call getChangedFieldValue try to use the 1-based index to identify a field.
I'm looking to dynamically populate a dojo combobox with values that come from a json rest api. Ideally, the user inputs their string into the combo box, a 'get' call is made returning related strings, and the select options are populated with these results.
The JsonRest store seems like a good way to go about doing this, but so far my attempts have been unsuccessful. I am encountering two issues:
My rest api returns a list of strings, while the combo button is expecting a list of objects with specified keys to use as the names/values. I don't have access to the api so I can't change the response structure. -Fixed
The 'get' calls that the json rest store is making is adding an asterisk on to the end of the query, which isn't desirable. -Fixed
My setup looks like this:
this.testStore = new JsonRestStore({
target: "myUrl",
allowNoTrailingSlash: true
});
this.dapComboBox.set('store', this.testStore);
this.dapComboBox.set('searchAttr', 'tag');
Update 1
I've figured out the asterisk issue, it was fixed by setting the combo box's 'queryExpr' attribute to '${0}'
Update 2
I solved the unusable list issue by creating my own basic store with get, getIdentity, and query functions. In my new query function I returned a new deferred object. I processed the returned values from the get request to fit the proper format and resolved this new list with my new deferred.
Issue 1: Fixed by setting the combo box's 'queryExpr' attribute to '${0}'
Issue 2: Created my own basic store with get, getIdentity, and query functions to fix. In my new query function I returned a new deferred object. I processed the returned values from the get request to fit the proper format and resolved this new list with my new deferred.
I hope I can expain myself what I mean.
Let's say I have a car resource. The car has the attributes color, name or whatever.
I get the list of cars using a service, something like cars.index().
But in the interface I have all the cars and when I click on one car, a little popup appears showing the inputs to edit the color and the name.
And here comes the issue. Where do I save the displayingInputs attribute?
Should I save it directly in the car resource and then just send the original attributes when submitting to the updated resource?
Should I create a new service called carWidget or something along the lines that each one has something like:
{
car: cars.get(carId),
displayingInputs: false
}
Should I store the displayingInputs inside a carWidget directive scope? What happens if I need to change the `displayingInputs from the parent scope? (for example when making a "display all"/"hide all" button)
Something else?
My best bet is #3, but I'm not sure how should I access the displayingInputs from outside the widget.
If you want to keep your car model clean, you can have a separate variable editedCar and display each popup with ng-show="car == editedCar".
If multiple cars can be edited at the same time, editedCars can be an associative array (car ID => boolean) and display popups using ng-show="editedCars[car.id]".
Another way not to send certain car properties is to prefix their name with a $ sign. This was simply use car.$displayingInputs. Be careful for name collisions as Angular uses this prefix to store internal data.
From the angular.toJson doc:
Serializes input into a JSON-formatted string. Properties with leading
$ characters will be stripped since angular uses this notation
internally.
I wish to save my view model to a database as a JSON string. The idea is that I can then re-load my view model by reading the JSON back and using the direct approach to load my view model's data:
From the Knockout documentation:
// Load and parse the JSON
var someJSON = /* Omitted: fetch it from the server however you want */;
var parsed = JSON.parse(someJSON);
// Update view model properties
viewModel.firstName(parsed.firstName);
viewModel.pets(parsed.pets);
That all works great but where I've already initialised my model and I'm simply updating it with one that I've already saved, I can't see how I can select the originally selected entry in the array's drop-down list.
To put it another way, the pets drop-down list is selected as "Cat" when I save my model. I then change the drop-down list selection to "Dog". On re-loading the saved model, I need my drop-down list selection to be reset to "Cat".
I'm a bit concerned about this because I have some arrays of objects which also need to be read in from the saved model and it's looking like it's going to be very difficult to do.
Any ideas or suggestions are welcome :)
What you are looking for is the mapping plugin for Knockout. http://knockoutjs.com/documentation/plugins-mapping.html
It has methods that handle both JSON to observables and back.
So in your example you could do:
var viewModel = ko.mapping.fromJSON(someJSON);
And when you're ready to go back to the server:
var jsonData = ko.mapping.toJSON(viewModel);
There are also object literal helpers if you need that (ko.mapping.toJS & ko.mapping.fromJS)