Aurelia:更改可绑定的名称(属性)

时间:2017-05-24 06:18:09

标签: aurelia aurelia-binding

我想知道是否可以更改Aurelia中可绑定的名称(HTML中的属性名称)。由于我们在当前项目中使用的编码标准,我们使用的属性名称非常难看,例如:m-data="someData"。我们为所有班级成员添加m作为前缀。我知道我可以在课堂上使用它,所以自定义元素名称是可自定义的,但是我也可以为bindables做这个吗?

例如:

// my-component.js

// I can use a decorator here to
// change the custom element name, which is great!
@customElement('my-component')
export class clsMyComponent {
  @bindable mData;
}

结果如下:

<!-- index.html -->

<my-component m-data.bind="someData"></my-component>

所以我想做的,但不起作用,是:

@customElement('my-component')
export class clsMyComponent {
  @bindable({name: 'data'}) mData;
}

我无法在此找到任何内容,我知道你可以设置双向绑定,默认值等等。但是这个名字不对吗?任何帮助将不胜感激!

1 个答案:

答案 0 :(得分:7)

因此,经过一些研究,我发现了这个问题的正确答案。如Aurelia docs中所述(搜索&#39;可绑定签名&#39;)。您可以像这样设置属性名称:

commands = {
'help': help,
'exit': exit,
'look': look,
'stats': thePlayer.printStats,
's':thePlayer.move_South}

def runCmd(cmd, args, player):
    commands[cmd](args, player)

def help(args):
    print(commands)

def play():
    main1()
    World.loadTiles()
    #These lines load the starting room and display the text
    room = World.tileExists(player.locationX, player.locationY)
    print(room.introText())
    while player.isAlive():
        room = World.tileExists(player.locationX, player.locationY)
        room.modifyPlayer(player)
        # Check again since the room could have changed the player's state
        if player.isAlive():
            print("\nHp:%d\%d  Mp:%d\%d\n"%(player.hp,player.maxHp,player.mp,player.maxMp))
            print(room.printEnemy())
            availableActions = room.availableActions()            
            for action in availableActions:
                print(action)
            actionInput = input('Action: ')
            action = actionInput.lower()
            action = action.split()            
            print(action)
        if action[0] in commands:
            runCmd(action[0],action[1], player)

生成的HTML:

@customElement('my-component')
export class clsMyComponent {
  @bindable({attribute: 'data'}) mData;
}