SAPUI5 oModel.create() with Array [closed] - odata

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 2 years ago.
Improve this question
I have a OData Model in my application, where I want to add a new entry.
This code works fine in my case:
ODataModel.createEntry("/showcaseSet", {
properties: {
"property": "Haris"
}
});
But when I am doing the same with array it doesnt work:
var oEntry = [];
oEntry.push(
{
"property": "Haris"
}
);
ODataModel.createEntry("/showcaseSet", oEntry);
When I am submitting the chages from the Model to my backend, I don't recieving any data from the frontend. Only when I am working in the first case or code i described.
Do you know where my problem is?

In v2.ODataModel, the createEntry API is expecting just an object in the second argument, not an array.
In that case, you could do something like this:
oEntry.forEach(e => ODataModel.createEntry("/showcaseSet", e));

// binding against this entity
oForm.setBindingContext(oContext);
// submit the changes (creates entity at the backend)
oModel.submitChanges({success: mySuccessHandler, error: myErrorHandler});

Related

Function should be called until my array become empty [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 5 years ago.
Improve this question
I'm having an array of data, i need to call a API Function and use my array value. Each time the API is hitting respected value should be deleted and my function should be called until the array becomes empty.
Try this example.
call this method process first time and pass your array like
process(array)
it will call itself until array contains element/s.
let array = [1,2,3]
func process(_ array: [Int]){
if array.isEmpty{ return }
let element = array.first!
//process element
print(element)
let newArray = Array(array.dropFirst())
process(newArray)
}

Saving Data In Swift [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
In my application I created a structure with two properties:
struct questionCollection {
var question: String!
var answer: String!
}
I then created an instance of that:
questionCollections = [questionCollection(question: "What is 1+1?", answer: "2")]
Along with this I have a function that allows the user to add a question:
#IBAction func appendQuestion(sender: AnyObject) {
questionCollections += [questionCollection(question: questionInput.text, answer: answerInput.text)]
}
My question is what is the easiest way to save the user submitted data? I have only used NSUserDefaults before and I don't know what to do.
I really couldn't find any solution to my problem so if I could get some help that would be great. Thanks
To clarify: All I want to do is have the data stored so can be shown on a label and check to see if the correct answer is chosen. The data does not need to be seen by the user until it comes up in the label. I am also just creating a simple app so I only need this data to be saved on the device.
With what I am doing now I am not sure if I need to save my data but if someone can still answer this if they want for future reference.
Have you ever tried using Core Data before? It is Apple's default solution for persistent storage (saving things locally and having them appear again on every load of the app) . More information can be found here. https://developer.apple.com/library/watchos/documentation/Cocoa/Conceptual/CoreData/index.html
Currently, your structure can be represented as a dictionary value:
let dictionary:[String:String] = ["What is 1+1":"2", "What is 2+2": "4"]
and you can store a dictionary inside NSUserDefaults:
NSUserDefaults.standardUserDefaults().setObject(dictionary, forKey: "aKey")
I would say, this would be optimal solution in you case ...

Assigning to 'readonly' return result [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I'm trying to reset the state of this statement:
[[IAPManager sharedInstance]isProductPurchased:kInAppItem] = FALSE;
However, i'm getting the error of "Assigning to 'readonly' return result of an Objective-C message not allowed". How do i reset the state of this statement?
In IAPManager.m
-(BOOL)isProductPurchased:(NSString *)productIdentifier
{
return [_purchasedProducts containsObject:productIdentifier];
}
Your left hand side is a method invocation that returns a BOOL, it is not a reference to the property itself, so you cannot assign a value.
You need to refer to the code for IAPPurchase, but if it this library then there is no method to reset the purchased state for a product.
You can delete the app or delete the plist the library uses to store purchase data (by the way, this isn't a very secure way of recording in-app purchases)
You can't assign a value to a return value of a method in Objective-C. You may be confused by the syntax
myObject.myProperty = myValue;
This sets the value of myProperty to myValue, but in doing so it essentially calls this method:
[myObject setMyProperty:myValue];
Either way, the left side of your code will be handled as a return value, not a property. Therefore you can't assign it.
If there exists a method like setProductPurchased: or setIsProductPurchased:, you need to call that like the second example. Otherwise there isn't a way to set the property, so you may have to set an instance variable directly.

Angular, watch a variable update via AJAX [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions concerning problems with code you've written must describe the specific problem — and include valid code to reproduce it — in the question itself. See SSCCE.org for guidance.
Closed 9 years ago.
Improve this question
I have a cart controller, that manages cart in e-store. Ordered products are stored in scope.cart. In view I have buttons to change item's cnt, like <elem ng-click="inc(c)" />, so inc function incrementing c.cnt
Now, I want to watch cart object, so on cnt change I can make XHR call to change data in user session. That's ok and working fine, the problem is I have some difficult pricing rules, so I have to return prices manually within same XHR query, and update scope.cart. This makes a loop, and I wonder how do I make things proper, angular-way?
You don't have to watch the cart object changes if you have a function that increments the cart items.
i.e
$scope.inc = function(c) {
// Do your cart logic here and then
$http({method: "PUT", url: "/cart"})
.success(function(data, status, headers, config) {
// update cart object with new pricing rules
})
.error(function(data, status, headers, config) {
// handle errors
});
};

Rails, two part of string one is text and second is attached variable.error occur to display part one [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
Lets consider the string "My name is #{#user.name}"
So i need to check and handle the error in this part "#{#user.name}".
Error may be because of "#{user.name}" (user object is undefined) or "#{other_object.name}"
or accessing the attribute that does not belong to the user table.
You can use:
name = "#{object.name}" if object.respond_to?(:name)
If object doesn't respond to #name method (it also handles the case when object is nil), nil will be assigned to name variable.
Try this
"My name is #{#user.try(:name)}"
TRY method will return nil if it caught exception, it wont throw any error.
Simple error handling
begin
string = "My name is {#user.name}"
rescue
string = "My name is not currently available"
end

Resources