是否可以影响位于两个ng-repeat指令内的div的唯一ID?见下面的例子:
<!--first ng-repeat-->
<div id = "1">
<div id = "2">
<div id = "3">
<div id = "4"> <!--start second array-->
<div id = "5">
预期产出:
<div id = "1">
<div id = "2">
<div id = "3">
<div id = "1"> <!--start second array-->
<div id = "2">
不
var mutableData: NSMutableData = NSMutableData.init();
var currentElementName: NSString = "";
@IBAction func btnDeneme(_ sender: Any) {
let soapMessage = "<?xml version=\"1.0\" encoding=\"utf-8\"?><soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\"><soap:Body><CelsiusToFahrenheit xmlns=\"http://www.w3schools.com/xml/\"><Celsius>10</Celsius></CelsiusToFahrenheit></soap:Body></soap:Envelope>"
let url = "http://www.w3schools.com/xml/tempconvert.asmx?op=CelsiusToFahrenheit"
let urlStr = NSURL(string: url)
let request = NSMutableURLRequest(url: urlStr as! URL)
let msgLength = soapMessage.characters.count
request.addValue("text/xml; charset=utf-8", forHTTPHeaderField: "Content-Type")
request.addValue("http://tempuri.org/CelsiusToFahrenheit", forHTTPHeaderField: "SOAPAction")
request.addValue(String(msgLength), forHTTPHeaderField: "Content-Length")
request.httpMethod = "POST"
request.httpBody = soapMessage.data(using: String.Encoding.utf8, allowLossyConversion: false)
let connection = NSURLConnection.init(request: request as URLRequest, delegate: self)
}
private func connection(connection: NSURLConnection!, didReceiveResponse response: URLResponse!) {
mutableData.length = 0;
}
private func connection(connection: NSURLConnection!, didReceiveData data: Data!) {
mutableData.append(data)
lblSonuc.text = String(describing: data) }
func connectionDidFinishLoading(connection: NSURLConnection!){
let response = NSString(data: mutableData as Data, encoding: String.Encoding.utf8.rawValue)
lblSonuc.text = response as String?
//let xmlParser = XMLParser(data: mutableData as Data)
//xmlParser.delegate = self
//xmlParser.parse()
//xmlParser.shouldResolveExternalEntities = true;
更新:我不认为track by或$ parent。$ index适用于这个用例,显然我们必须计算每个子数组的长度才能获得精确递增的计数器。我正在尝试两个ng-init的组合。一旦我开始工作,我会更新帖子
答案 0 :(得分:0)
我终于开始工作,这是我的尝试:
<div ng-repeat = "item in data" ng-init = "count = 0">
<div ng-repeat = "sub-item in item" ng-init="count = count + data[$parent.$index -1].length">
<div id = "{{count+$index+1}}">
</div>
如果您有更合适的解决方案,请随时编辑