Here I have an Objective - C Method:
+(void)postSaveCoinOrder:(OrderSaveCoinOrderRequestModel *)model returnInfo:(void(^)(OrderSaveCoinOrderResponseModel* resModel))retMode;
and I want call it in Swift file. tried many times but don't work.
Can someone help me?
Try this...
let request = OrderSaveCoinOrderRequestModel.init()
CLASS_NAME.postSaveCoinOrder(request) { (response) in
}
CLASS_NAME is the name of the class where postSaveCoinOrder is defined.
Have you add a bridge file in your project?
If so, code like this...
let model = OrderSaveCoinOrderRequestModel()
CLASSNAME.postSaveCoinOrder(model: model, returnInfo: {
(retModel: OrderSaveCoinOrderRequestModel) -> () in
...
})
I think this will be more detailed.
Related
My directory looks like bellow
--controllers
-helper.js
--models
-userModel.js
--server.js
My helper module is like
module.exports = {
check: function() {
return 'check';
}
}
I want to access helper module inside userModel.js. So I put like
var helper = require('.././controllers/helper');
Then I do console.log(helper.check()); but it shows error helper.check is not a function Or if I do console.log(helper); only it returns {}. How to access the helper module inside models? Thank you.
Since you said it returns {}, can you please check in your helper module that you have imported userModel.js. Because it forms circular dependencies and sometimes result empty json.
For example i do
* def fooresponse = call read('../getfooid.feature')
* def jsfunction= """(fooresponse){
console.log(fooresponse)}"""
is that possible? what is the recommended way to do it?
Thanks!
edit: fixing js syntax lol
Yes, this will work if the function has been defined after the variable fooresponse:
* def jsfunction = function(){ karate.log(fooresponse) }
Yes, you can pass a single argument to karate.call().
Keep in mind that the #(foo) substitution does NOT apply to pure-JS, explained here: https://github.com/intuit/karate#karate-expressions
I think once you read the above link AND if you are familiar with JS, you will know what to do.
Like this:
* def fun = function(){ karate.call('foo.feature', { bar: 'baz' }) }
Hi I am new to expressjs. I have an admin route where I would like admin to update record and etc. I don't want to write code to updated record under the route rather I just to pass some functions or object that fetch records from db or updated them. I am using passportjs for authenticate. Currently my route look like this -
app.get('/admin', function(req, res){
res.render('admin', {
title: "Welcome Member_name ",
user: req.user
});
});
So I have created another js file for all admin operation. its under root/controller/admin.js and its looks like this -
var mysql = require('mysql'),
dbconfig = require('../config/database'),
connection = mysql.createConnection(dbconfig.connection);
module.exports = {
}
what I am after is to write some function that will get some data from the database and return the object so that I can pass the object to my route and from there to the view. Can anyone help me plz? thanks. Also if you know best practice for learning expressjs plz let me know. Thanks a lot in advance. Cheers.
I'll try to answer this one for you, although you question was a bit muddy to understand. If I'm right you'd like to call a method in your module from your route?
Let us say your module file was called admin.js for the following example. This is how you would create a method accessible outside of the module.
admin.js
var mysql = require('mysql'),
dbconfig = require('../config/database'),
connection = mysql.createConnection(dbconfig.connection);
module.exports = {};
module.exports.retrieveData = function() {
//Data retrieval code here.
};
Then in your routes file, let us say routes.js for the example. This is how you would call the method.
routes.js
var admin = require('./admin.js') //Remembering to require the module!
database.retrieveData();
You would then pass your query through a parameter in the retrieveData() method.
I am trying to build a relatively simple web application following tutorials from the book ProAngular. The book examples work fine, but when I try and build my own app, I am getting stuck on a strange error. Here is part of my code:
$scope.dispositionsResource = $resource(dispositionUrl + ":id", { id: "#id" },
{ create: {method: "POST"}, save: {method: "PUT"}, delete: {method: "DELETE"}
});
. . .
$scope.updateDisposition = function (disposition) {
alert("DISPOSITION: "+disposition.name);
disposition.$save();
}
The Create and Delete functions work fine. The updateDisposition method is being called form an HTML form and the correct disposition value is being passed (based on the Alert). But the error I am getting is:
"Error: disposition.$save is not a function"
None of my example code separately defines a save function, the function should be part of the restful service ($resource). Shouldn't it?
Any pointers in the right direction would be greatly appreciated.
Ted
I did end up getting this working. Not totally sure why, but I renamed the Save function to 'Update' and associated it with the PUT functionality.
$scope.dispositionsResource = $resource(dispositionUrl+":id", { id: "#id" },
{ 'create': {method: "POST"}, 'update': {method: "PUT"}
});
$scope.updateDisposition = function (disposition) {
$scope.dispositionsResource.update(disposition);
$scope.editedDisposition = null;
}
calling update rather than save worked. Something seemed to be interfering with using the term 'save'. Like I said, not sure what . . . yet. One of those head-scratchers for me. Thanks to those who tried to assist!
I am learning angular myself, but the first problem I can see with your code is that it doesn't look like you are defining $resource correctly ( fair warning, Angular has a ton of caveats and you may simply be delving into one I am not aware of).
I believe a more straight forward way of doing what you are trying to do is first creating an angular factory for the $resource, like so:
angular.module('yourModuleName')
.factory('disposition', function($resource) {
return $resource('/whatever/url/youwant/:id', {
id: '#id'
})
});
And then from there, declare the factory as a dependency for your controller:
angular.module('yourModuleName')
.controller('yourControllerName', function($scope, disposition) {
$scope.submitForm = function($scope)
disposition.save($scope.nameOfYourModel);
});
One thing to keep in mind is that $resource has all of the methods that you declared by default. From the docs at https://docs.angularjs.org/api/ngResource/service/$resource these are what are available out of the box:
{ 'get': {method:'GET'},
'save': {method:'POST'},
'query': {method:'GET', isArray:true},
'remove': {method:'DELETE'},
'delete': {method:'DELETE'} };
Personally, I prefer to use the $http service myself. Yes, it is quite a bit more verbose than using $resource but I feel that it is much easier to understand $http when starting with angular than the $resource service. To save yourself from a world of headaches in the future, I highly recommend becoming familiar with the concept of promises in Angular as many of its services make use of them.
Good luck.
Say I have a class in Coffeescript:
class MyGame
constructor: () ->
#me = new Player
#opponents = [new Player, new Player]
which would like to test in Jasmine:
describe "MyGame", ->
beforeEach ->
window.game = new MyGame
it "should have two players", ->
expect(window.game.opponents.length).toEqual 2
But I get the error TypeError: Result of expression 'window.game.opponents' [undefined] is not an object.?
The window.game approach also seem awkward to me. If I try to define it as #game = new MyGame I get the error ReferenceError: Can't find variable: MyGame but I guess that has something to do with the way Coffeescript is wrapping things up?
UPDATE: The problem seems more like a reference problem as described above. I'm running with guard-jasmine which looks like
guard 'jasmine', :all_on_start => false, :all_after_pass => false do
watch(%r{app/assets/javascripts/(.+)\.(js\.coffee|js)}) { |m| "spec/javascripts/#{m[1]}_spec.#{m[2]}" }
watch(%r{spec/javascripts/(.+)_spec\.(js\.coffee|js)}) { |m| "spec/javascripts/#{m[1]}_spec.#{m[2]}" }
watch(%r{spec/javascripts/spec\.(js\.coffee|js)}) { "spec/javascripts" }
end
and my jasmine.yml file has:
src_files:
- "app/assets/**/*.js"
- "app/assets/**/*.coffee"
spec_files:
- '**/*[sS]pec.js.coffee'
asset_pipeline_paths:
- app/assets
- spec/javascripts
I get the an ReferenceError: Can't find variable: MyGame so I figure it's either something with the Rails 3.1 asset pipeline or the way Coffeescript wraps objects.
try defining your coffeescript class using the # operator as such:
class #MyGame
constructor: () ->
#me = new Player
#opponents = [new Player, new Player]
this will allow you to access the class from anywhere, such as from your jasmine tests, and also you can get away from attaching testing variables to window:
describe "MyGame", ->
beforeEach ->
#game = new MyGame
it "should have two players", ->
expect(#game.opponents.length).toEqual 2
the reason for this is that coffeescript goes out of its way to avoid introducing global variables by wrapping everything in a closure. unfortunately, this can be undesirable for object-oriented code. using the # operator attaches the class definition to the global this, which is window, and thus allows you to instantiate your classes as you like. you may have some global vars in your global space now, your classes, but for me its an ok trade-off. hope this helps!
I wasn't willing to accept modifying the namespace of my code by using an # symbol in front of all my backbone classes, so I dug around some more and the solution that worked for me was to require the application file in my spec/javascripts/spec.js.coffee file
#= require application
window.game = () -> new MyGame
This will assign a function that returns a new MyGame to window.game. Did you not just want the new instance directly?
window.game = new MyGame
The window.game approach also seem awkward to me.
How about this
describe "MyGame", ->
game = null
beforeEach ->
game = new MyGame
it "should have two players", ->
expect(game.opponents.length).toEqual 2
I have solved the problem by defining every class as class window.MyGame for example. In the spec files I put #= require my_file_name in the top.
Furthermore I have placed both jasminerice.js.coffee and jquery.js in app/assets/javascripts. This might not be the best solution as I assume they should be placed in spec/javascripts/helpers as my spec.js.coffee's content is #=require_tree ./.
I'm aware that this is not very elegant but it might help others in the same situation. #Thilo thanks for your inputs.