I've created a JSON model in a controller, and I have nice data list there...
but I do not know how to access this list/model via corresponding view. Help?
You can set model in controller:
`sap.ui.getCore().setModel(jsonModel,"NAME");`
and get this model in View (JS view) with:
`sap.ui.getCore().getModel("NAME");`
Related
I have a User model and having has_many associations with Note model.
Getting the records in an array format. I have to show content(column of note model) only.
So, Fetching data using:
#user.notes.pluck(:content).
It is giving like this.
["Testing Notes123", "Testing Notes12345"].
In UI I want to display like this:
Testing Notes123
Testing Notes12345
Could someone please help me to fix this.
By the "UI" do you mean a web page? That would involve a controller and a view. If you're just talking about the console, then this should do it:
notes = #user.notes.pluck(:content)
notes.each do |note|
puts note
end
Or:
notes = #user.notes.pluck(:content)
puts notes.join("\n")
I am working on a Master-Detail app. I have a view with list control and I am binding the same with the data from an entityset called "entityset1".
Odata -> data from the entityset1
<serialno>122333</serialno>
I do have another entityset called entityset2 in the same service.
Odata -> data from the entityset2
<hdata>is Active</hdata>
Data from above entityset2 will only be retrieved with the filter (/sap/opu/odata/sap/My_SRV/entityset2?$filter=(serialno=122333)
I am now trying to retrieve the value from the entityset2 and trying to bind it to one attribute in my list. This list is already binded with the entityset1 data.
Myview.xml.
<List id="list" select="_handleSelect">
<ObjectListItem id="MAIN_LIST_ITEM" press="_handleItemPress" title="{Name}">
<attributes>
<ObjectAttribute id="ATTR1" text="{serialno}" />
<ObjectAttribute id="ATTR2" text="{entityset2/hdata}" />
</attributes>
</ObjectListItem>
</List>
Controller.js (binding using the below lines)
this.oList.bindAggregation("items", {
path: '/entityset1',
template: this.oListItem,
filters: this.searchFilters
});
var oserialnum = this.getView().getBindingContext().getObject().serialno;
var oHdata = new sap.ui.model.Filter("serialno", "EQ",oserialnum);
this.searchFilters = new sap.ui.model.Filter([oserialnum],true);
this.oList.bindAggregation("items",{
path : "/entityset2",
filters :this.searchFilters
});
However I am getting an error "Cannot read property 'getObject' of undefined" on this line "this.getView().getBindingContext().getObject().serialno".
Can someone kindly advise how to retrive the data from the entity2 and binding it to the list, ?
You cannot get BindingContext using the view. Read more about binding Context - it's a pointer to an object in Model data.
Also, serialNo(the parameter you are trying to retrieve from the Model is also contextual i.e. it differs with each row item).
One way to do this would be:
onListeItemPress Event of the List
<ObjectListItem ... ... press="onListItemPress" >
In the corresponding Controller
`onListItemPress : function(oEvent){
var oserialnum = Event.getSource().getBindingContext("mainODataModel")..getProperty("serialNo")`
Let me know if this helps.
If I understand you correctly what you need is associations.
They will allow the OData Service to deliver the needed Data from entityset2 directly with the entityset1 through "associating" entityset2 with your serial number.
If you are using a SAP Backend and SEGW this Blog might help you:
https://blogs.sap.com/2014/09/24/lets-code-associationnavigation-and-data-provider-expand-in-odata-service/
I was faced with a similar issue whilst creating a Master-Detail App, but found out from the SAP Forums that this is not possible, which makes sense and ended up creating a separate entityset in the Backend having a link to the other set
I'm trying to push data from a link within my grid data UI, when you click the link, open a popup (which I do with a modal fine) however when the modal opens, I can't access any of the data that was defined in the other controller.
This snippet:
<a href ng-click="grid.appScope[col.field](row.entity)">Popup</a>
Works fine, where it shows the col.field value, however I'd like to show data within the popup from grid.appScopecol.field in the popup - however that is another controller, how would I handle passing data from one controller to another within this format?
My suggestion is just pass those data into angular service define a service like
angular.service('MyService', function() {
//if you want Object format or
this.controller1Data = {};
//if you want array format
this.controller1Data = {};
});
in your controller just pass the data into that service like
//In controller
MyService.controller1Data = //Pass the data to that service;
then in HTMl
<a href ng-click="//call that method()">Popup</a>
Is it possible to access the model in the PartialView returned by RenderAction from the parent view?
I have a controller action that returns a view with a list of items that have geographical data. I'd like to use the lat/lon to place the items on a map as well, but I don't want to have to parse the html for the data.
I have some json attached to a data attribute on a page. The json data is used to build a table in angularjs.
I'm using coffeescript and haml.
app = angular.module("myApp", [])
app.controller "TableCtrl", ($scope) ->
$scope.table = $("#mydata").data("myjson")
#table{"ng-app"=>"myApp","ng-controller" =>"TableCtrl"}
%table
%tbody
%tr{"ng-repeat"=>"(i,item) in table" }}"}
%td {{item.name}}
The page loads the data into a table. Elsewhere on the page the json on the data attribute can be changed by a user with jquery. How can I have 2-way binding between the json data and the table? i.e I want the table to change as the json on the data attribute is changed locally.
What you need is to tell AngularJS to observe $("#mydata").data("myjson") for any changes and then update $scope.table when a change occurs. Try adding the following code to your controller (sorry I don't know coffeescript).
$scope.$watch(
function () { return $("#mydata").data("myjson");},
function(newJson) {
$scope.table = newJson;
},
true
);