对于在GOlang中整理XML:字段为空感兴趣的读者,本文将会是一篇不错的选择,我们将详细介绍APPEND不起作用?,并为您提供关于AndroidXML:在相对布局中居中视图–android:layo
对于在GOlang中整理XML:字段为空感兴趣的读者,本文将会是一篇不错的选择,我们将详细介绍APPEND不起作用?,并为您提供关于Android XML:在相对布局中居中视图 – android:layout_centerHorizontal =“true”不起作用?、angular 2 ViewChild不起作用、angularjs – ng-click对通过jquery append创建的链接不起作用、angularjs – 为什么ng-disabled不起作用?的有用信息。
本文目录一览:- 在GOlang中整理XML:字段为空(APPEND不起作用?)(golang xml)
- Android XML:在相对布局中居中视图 – android:layout_centerHorizontal =“true”不起作用?
- angular 2 ViewChild不起作用
- angularjs – ng-click对通过jquery append创建的链接不起作用
- angularjs – 为什么ng-disabled不起作用?
在GOlang中整理XML:字段为空(APPEND不起作用?)(golang xml)
我正在学习在Go中创建XML。这是我的代码:
type Request struct { XMLName xml.Name `xml:"request"` Action string `xml:"action,attr"` ... Point []point `xml:"point,omitempty"`}type point struct { geo string `xml:"point"` radius int `xml:"radius,attr"`}func main() { v := &Request{Action: "get-objects"} v.Point = append(v.Point, point{geo: "55.703038, 37.554457", radius: 10}) output, err := xml.MarshalIndent(v, " ", " ") if err != nil { fmt.Println("error: %v\n", err) } os.Stdout.Write([]byte(xml.Header)) os.Stdout.Write(output)}
我希望输出是这样的:
<?xml version="1.0" encoding="UTF-8"?> <request action="get-objects"> <point radius=10>55.703038, 37.554457</point> </request>
但是我得到的是:
<?xml version="1.0" encoding="UTF-8"?> <request action="get-objects"> <point></point> </request>
我想念什么或做错什么?因为“ name,attr”东西对其他所有东西都适用(例如,如您所见,对于“ request”字段)。谢谢。
答案1
小编典典您的代码中有几处错误。在Go中使用编码包时,所有要编组/解组的字段都必须导出。请注意,结构本身不必导出。
因此,第一步是更改point
结构以导出字段:
type point struct { Geo string `xml:"point"` Radius int `xml:"radius,attr"`}
现在,如果要Geo
在点内显示字段,则必须添加,cdata
到xml标记中。最后,无需向omitempty
切片添加关键字。
type Request struct { XMLName xml.Name `xml:"request"` Action string `xml:"action,attr"` Point []point `xml:"point"`}type point struct { Geo string `xml:",chardata"` Radius int `xml:"radius,attr"`}
去操场
Android XML:在相对布局中居中视图 – android:layout_centerHorizontal =“true”不起作用?
但它不起作用,而是位于屏幕左侧.
为什么不,我该如何解决这个问题呢?
完整的XML:
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" android:background="@drawable/menubackground" > <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical" > <TextView android:id="@+id/tvStroopColor" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" android:paddingBottom="3dp" android:layout_marginTop="11dp" android:layout_marginBottom="15dp" android:text=" " android:textSize="50dp" android:background="#ffffff"/> </LinearLayout> <LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="horizontal" android:gravity="center" > <Button android:id="@+id/btnStroop1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text=" " android:textSize="40dp" /> <Button android:id="@+id/btnStroop2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text=" " android:textSize="40dp" /> </LinearLayout> <RelativeLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <TextView android:id="@+id/tvStroopResults" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" android:paddingBottom="3dp" android:text=" " android:layout_centerHorizontal="true" android:textSize="35dp" /> <TextView android:id="@+id/tvStroopscore" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@+id/tvStroopResults" android:layout_centerHorizontal="true" android:paddingBottom="3dp" android:text=" " android:textSize="35dp" /> <TextView android:id="@+id/tvStroopSeeMeditation" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@+id/tvStroopscore" android:layout_centerHorizontal="true" android:paddingBottom="3dp" android:text=" " android:textSize="35dp" /> <TextView android:id="@+id/tvStroopSeeAttention" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@+id/tvStroopSeeMeditation" android:layout_centerHorizontal="true" android:layout_marginTop="4dp" android:text=" " android:textSize="35dp" /> <TextView android:id="@+id/tvStroopCountdown" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_below="@+id/tvStroopSeeAttention" android:layout_centerHorizontal="true" android:ems="10" android:textSize="30dp" android:hint=" " > </TextView> </RelativeLayout> </LinearLayout>
解决方法
angular 2 ViewChild不起作用
模板:
<div #refId> {{lineNumber}} </div>
零件:
import {Component,OnInit,Input,ElementRef,ViewChild} from '@angular/core'; import {Globals} from "../../../globals"; @Component({ selector: 'app-line-counter',templateUrl: './line-counter.component.html',styleUrls: ['./line-counter.component.css'] }) export class LineCounterComponent implements OnInit { @ViewChild('#refId') textDiv:ElementRef; @input() lineNumber : number = 0; constructor() { } ngOnInit() { if(Globals.refLineCounter == null) { Globals.refLineCounter = this; //console.log(Globals.refLineCounter.getHeight()); console.log(this.getHeight()); } } getHeight(){ return this.textDiv.nativeElement.height; } }
解决方法
@ViewChild('refId') textDiv:ElementRef;
其次,ViewChild变量在AfterViewInit生命周期之前未初始化,因此您需要将代码从ngOnInit移动到ngAfterViewInit:
ngAfterViewInit() { if(Globals.refLineCounter == null) { Globals.refLineCounter = this; //console.log(Globals.refLineCounter.getHeight()); console.log(this.getHeight()); } }
angularjs – ng-click对通过jquery append创建的链接不起作用
<divid="cModal" ng-controller="modalController"> <li id="modalp1"><a ng-click="parentOptions()" href="#">Add Parent</a></li> </div>
如果通过jquery append()或prepend()方法动态创建示例链接,则单击事件不起作用.示例代码如下所示.
$('#cpartners').prepend("<li><a ng-click=\"parentOptions()\" href=\"#\">Add Parents (Mother & Father)</a></li>");
控制器示例代码如下所示
function modalController($scope) { $scope.sthumbedit = function() { $(".dur").show(); }; $scope.hthumbedit = function() { $(".dur").hide(); }; $scope.parentOptions = function() { prepareParentOptions(); }; $scope.siblingOptions = function() { prepareSiblingOptions(); }; $scope.childOptions = function() { prepareChildOptions(); };
}
有没有办法强制执行ng-click属性在dyanmically生成的链接上运行良好.
解决方法
var element = $compile(‘< p> {{total}}< / p>‘)(范围);
有关示例http://docs.angularjs.org/guide/compiler,请参见“如何编译指令”部分
angularjs – 为什么ng-disabled不起作用?
<inputng-model="ac.accesses.permision.alias" ng-disabled="true">
但输入标签不会禁用.
解决方法
Working Demo
<input type="text"ng-model="ac.accesses.permision.alias" ng-disabled="true">
Working Demo
<inputng-model="ac.accesses.permision.alias" ng-disabled="true">
今天关于在GOlang中整理XML:字段为空和APPEND不起作用?的分享就到这里,希望大家有所收获,若想了解更多关于Android XML:在相对布局中居中视图 – android:layout_centerHorizontal =“true”不起作用?、angular 2 ViewChild不起作用、angularjs – ng-click对通过jquery append创建的链接不起作用、angularjs – 为什么ng-disabled不起作用?等相关知识,可以在本站进行查询。
本文标签: