在我的程序中,我想使用变量设置ng-show
值,因此我随时更改ng-show
。
角度代码是:
var arrowup,arrowdown;
arrdown=false;
$scope.header=[{"name":"Subsection Header #1","arrowup":"arrowup","close":"close","arrowdown":"arrowdown","open":"open"}];
$scope.open = function() {
arrowdown = false;
arrowup = true;
}
我希望更改ng-show
的值,但不会更改。
html代码是:
<div class="arrow-down" ng-repeat="header in header" ng-click="this[header.open]()" ng-show="header.arrowdown ">
答案 0 :(得分:0)
您不能在Angular中使用绑定到模板,而是使用$scope
。
此外,您不能使用同名的ng-repeat
。
最后,没有必要将this[header.open]()
放在ng-click
中,只需使用open()
。
$scope.arrowdown=false;
$scope.header=[{"name":"Subsection Header #1","arrowup":"arrowup","close":"close","arrowdown":"arrowdown","open":"open"}];
$scope.open = function() {
$scope.arrowdown = false;
$scope.arrowup = true;
}
<div class="arrow-down" ng-repeat="head in header" ng-click="open()" ng-show="head.arrowdown">
答案 1 :(得分:0)
此代码将在点击时切换显示:
$scope.headers=[{"name":"Subsection Header #1","arrowup":"arrowup","close":"close","arrowdown":"arrowdown","open":"open", show: false}];
$scope.open = function(header) {
header.show = !header.show;
}
<div class="arrow-down" ng-repeat="header in headers" ng-click="open(header)" ng-show="header.show">
答案 2 :(得分:0)
目前尚不清楚你真正想要的是什么,我为你创造了样本:
ToString("dd-MMM-yyyy HH:mm:ss",CultureInfo.InvariantCulture);
&#13;
import UIKit
import Foundation
struct Player
{
var name:String?
var game:String?
var rating:Int
init(name:String?, game:String?,rating:Int)
{
self.name = name
self.game = game
self.rating = rating
}
}
let playersData = [
Player(name: "Bill Evans", game: "TTT", rating: 4),
Player(name: "OD", game: "Spin the Bottle", rating: 5),
Player(name: "DB", game: "Texas Holder", rating: 2)]
class PlayersViewController: UITableViewController {
var players:[Player] = playersData
override func viewDidLoad() {
super.viewDidLoad()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
// MARK: - Table view data source
override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
return 1
}
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return players.count
}
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell{
//This method will check to see if there is an existing cell that can be recycled.If not, it will automatically allocate a prototype cell and return it to you.
let cell = tableView.dequeueReusableCellWithIdentifier("PlayerCell", forIndexPath: indexPath)
let player = players[indexPath.row]as Player
cell.textLabel?.text = player.name
cell.detailTextLabel?.text = player.game
return cell
}
}
&#13;