- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
Aurelia 有字符串插值。如果将 string
、 number
或 boolean
绑定(bind)到该变量,则绑定(bind) one-way
。
但是,如果您绑定(bind)一个对象并使用 ValueConverter
,就像我想要的那样,它就会绑定(bind) one-time
。
如何使用值转换器来绑定(bind) one-way
而不是 one-time
?
我尝试过使用 ${data | objectPrinter & oneWay}
但不起作用。
Running code can be found on this gist
app.html
<template>
<div class="row">
<!-- this isn't updated on change -->
<pre>${data | objectPrinter}</pre>
</div>
<input value.two-way="data.branches">
<!-- this gets updated -->
${data.branches}
</template>
app.js
export class App {
data = {
branches: "test"
}
}
export class objectPrinterValueConverter {
toView(obj){
return JSON.stringify(obj, null, 4);
}
}
index.html
<!doctype html>
<html>
<head>
<title>Aurelia</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body aurelia-app>
<h1>Loading...</h1>
<script src="https://cdn.rawgit.com/jdanyow/aurelia-bundle/v1.0.3/jspm_packages/system.js"></script>
<script src="https://cdn.rawgit.com/jdanyow/aurelia-bundle/v1.0.3/config.js"></script>
<script>
System.import('aurelia-bootstrapper');
</script>
</body>
</html>
最佳答案
Aurelia 将绑定(bind)表达式的文本解析为抽象语法树 (AST),并使用它来确定要观察哪些属性。它仅观察表达式中引用的属性。
在您的示例中,绑定(bind)表达式如下所示:data |对象打印机
。该表达式访问 View 模型上的data
属性。这将使 Aurelia 观察数据属性的变化。 但它永远不会改变。在您的示例中, View 模型的数据属性保持相同的对象实例。唯一发生变化的是 branches
属性,该属性未在 objectPrinter 表达式中引用,因此它的更新不会导致该绑定(bind)重新评估。
这是创建对象打印机的另一种方法:
https://gist.run/?id=9eea8902521f4523ee2c
相关问题(忽略已接受的答案 - 它不适用于您的情况):
关于javascript - Aurelia 使用值转换器对打印值进行节流,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38326402/
我的 Tableview 有 N 个部分,其中 0,1 个部分是固定的。永远不会从 TableView 中删除。但从第2节开始到第N节,可以删除或插入。从第 2 部分到 N 部分 -> 每个部分也有行
节/段指令有多重要?我注意到它们通常是可选的。另外,我注意到当您包含或不包含它们时,输出大小会发生变化。 我正在使用NASM ,如果有帮助的话。 最佳答案 它们非常重要,因为如果将字符串保存在代码段中
我正在尝试使用已解析并存储在字典中的Firestore数据填充tableview的Sections and Rows,看起来像这样... dataDict = ["Monday": ["Chest",
所以这应该是相当基本的......我正在这样做,但我想要求一些不同的选择。 一种选择是使用“平滑滚动”和 anchor 名称......但我发现这非常不一致。 这是我的 HTML 结构:
我尝试将 3 篇文章嵌套到一个部分中。为什么它们会溢出部分的边界? CSS: article{ border-right:solid 1px grey; height:50%; width:30%;
早上好伙计们,这只是我在这里的第二个问题,所以请耐心等待我和我的最低要求: 我刚刚写了这篇冗长的消息,说明如何将 ID 和 class 命令放在 section 而不是 容器中,以及为什么该部分突然覆
我正在尝试使用以下代码段编码消息: JAXBContext jContext = JAXBContext.newInstance(Iq.class); Marshall
我正在尝试使用以下代码段编码消息: JAXBContext jContext = JAXBContext.newInstance(Iq.class); Marshall
我需要生成一个 PDF 文档,其中我需要一些“章节”(连同其部分和小节)没有编号但仍包含在 ToC 中。 这是我的硕士论文。我正在使用 book 文档类,因为我不喜欢 memoir 默认值。 如果我使
我正在使用正则表达式来尝试匹配 INI 文件中的节 block 。我正在使用书中给出的食谱Regular Expressions Cookbook ,但它似乎对我不起作用。 这是我正在使用的代码: f
我有一个多线程进程,其中文件由多个线程共享(读取和写入)。有没有什么办法可以让一个线程锁定一个文件段,使其他线程无法访问它?我尝试过fcntl(fd, F_SETLKW, &flock),但是这个锁只
Closed. This question needs to be more focused。它当前不接受答案。
我正在尝试使用以下代码片段编码消息: JAXBContext jContext = JAXBContext.newInstance(Iq.class); Marshal
我使用的是分段 tableView。如果我单击 tableview,它总是将索引路径 0 传递给详细 View Controller 。如果我单击第二行,但它的 indexpath pass 总是传递
我有一个多线程进程,其中一个文件由多个线程共享(读取和写入)。有没有什么方法可以让一个线程锁定一个文件段,使其他线程无法访问它?我试过fcntl(fd, F_SETLKW, &flock),但是这个锁
我正在尝试使用以下代码片段编码消息: JAXBContext jContext = JAXBContext.newInstance(Iq.class); Marshal
我想创建一个“术语”部分,其中包含我正在使用的术语的定义,以便每次我在此术语部分中使用这些术语时,都会创建一个指向该定义的链接。 目前,我能想到的最好的方法是: .. |flavor| replace
文档引用 configuring information with stanzas ,但什么是节? 它只是配置子部分的一个花哨名称吗? 最佳答案 您是对的,在此上下文中,节是指 IBM MQ 配置文件
我正在尝试在消息包中接收 XMPP 自定义节。例如, wololo haiooh ... 关键是我知道我会收到一个“custom_sta
为什么这是有效的: (= '(:anything :goes :here) (filter (fn [x] true) '(:anything :goes :here))) 但不是这个? (= (:a
我是一名优秀的程序员,十分优秀!