I am writing a class in coffescript and am able to add a class name with the following:
class Str extends Spine.Controller
className: 'myClass'
module.exports = Str
This outputs a div with the class 'myClass'. But how do I assign an element id??? I'm basically trying to output the following:
<div id="myId" class="myClass"></div>
Related
(First hours with AngularDart...)
The question's in the title. I have included:
import 'package:html/src/query_selector.dart';
and my function is:
void clickRadio() {
var ele=querySelector(node,'#idjoe1');
}
What do I use for node?
Thanks
Steve
dart comes with dart:html package with a nice query selector
import 'dart:html';
var ele = querySelector('#idjoe1');
<div id="idjoe1"></div>
but with angular2 you can use the ViewChild annotation inside you component
https://webdev.dartlang.org/angular/api/angular2.core/ViewChild-class
EDIT:
you also need this syntax if you want to use an other Angular2 component
#ViewChild('idjoe1')
MaterialRadioComponent radioComponent;
#ViewChild('idjoe2')
ElementRef ref;
HtmlElement get element => ref.nativeElement;
<material-radio #idjoe1></div>
<div #idjoe2></div>
In recent versions you can either inject an Element or HtmlElement in the constructor (which I think gives you the host element):
HtmlElement _host;
MyComponent(this._host);
Or you can use #ViewChild with an Element or HtmlElement:
#ViewChild('foo')
HtmlElement _foo;
...
<div #foo>
From a string I'm trying to instantiate a class (my marionette view). I found a way that works but this way has a problem where I can't actually pass a parameter to the instantiated class.
It seems when I call typeMapping[viewType] it's actually returning me Show.OneNode() instead of just Show.OneNode
class Show.TwoNode extends App.ItemView
template: "templates/two"
class Show.OneNode extends App.ItemView
template: "templates/one"
class Show.Layout extends App.Layout
onShow: =>
typeMapping = {
one: Show.OneNode
two: Show.TwoNode
}
viewType = "one"
view = new typeMapping[viewType]
model: #model
again, I would have rather made this a comment, but hey that's life. Have you tried wrapping your values from your key/value pairs in quotes to force them as strings?
typeMapping = {
one: "Show.OneNode",
two: "Show.TwoNode"
}
I have a record class like this:
class Address extends Record[Address] {
def meta = Address
object countryCode extends OptionalStringField(this, None) {
override def name = "Country"
var c = "" // this isn't doing anything but I set it up just to build the simple SHtml.select
override def toForm = Full(SHtml.select(List(("usa", "usa"),("ca", "ca")), Empty, c = _ ))
}
...
}
object Address extends Address with MetaRecord[Address] { }
and then this form is displayed like this:
object FormPage extends CssBoundLiftScreen {
def formName = "MyForm"
val record = Address.createRecord
field(record.countryCode, FieldBinding("addressCountryCode")
}
in a template like this:
<div class="form">
<div class="lift:FormPage">
<div class="fields">
<fieldset>
<div id="MyForm_addressCountryCode_field"></div>
</fieldset>
</div>
</div>
</div>
Is this the right way to do inputs other than a simple text field using Record/CssBoundLiftScreen? It doesn't seem like this select would update or create a record properly. How would I have the select show the value of the record field?
If you look at the scaladaoc for OptionalStringField, there are two methods that are provided through the superclass SettableValueHolder and that provide access to the underlying value: get and set
def set (in: Option[MyType]) : Option[MyType]
Set the value of the field to the given value. Note: Because setting a field can fail (return non-Full), this method will return defaultValueBox if the field could not be set.
get : Option[MyType]
get the value
I suspect something like this should work for you:
override def toForm = Full(SHtml.select(List(("usa", "usa"),("ca", "ca")), get, v => set(Some(v)) ))
I got an html-element aside.sidebar with an associated spine.js controller.
class App.Sidebar extends Spine.Controller
tag: 'aside'
className: 'sidebar'
how do i get the controller from the element? something like this:
con = $("aside.sidebar").spineController().someControllerMethod()
I'm using jquery + spine.js.
I've looked through the controller source code and it doesn't look like there is a built-in way to access the controller from the element (https://github.com/spine/spine/blob/dev/src/spine.coffee#L482). What I do is make a global variable to hold the controller so that I can access it from other places:
app = new App()
# inside of App constructor:
#foo_widget = new App.FooWidgetController()
# from other non-spine code:
app.foo_widget.method()
Another option would be to do the association yourself using jquery's data() method:
class App.FooWidgetController
constructor: ->
super
#el.data 'controller', this
# from other code:
$('#widget').data('controller').method()
I want to create objects in Ruby style with CoffeeScript. So I want to do something like
class A
constructor: (#params) ->
a = new A {send: true, name: "fit"}
a.send #true
Is there any "standard" way to do this?
There is no way to do it directly. You could define a base class that has code to do it, like such
class Base
constructor: (props) ->
for key, value of props
#[key] = value
class Extend extends Base
constructor: (props) ->
super props
alert "#{#key1}, #{#key2}"
e = new Extend 'key1': 'val1', 'key2': 'val2'
alert "#{e.key1}, #{e.key2}"
See it working here