使用三元运算符进行数据绑定以对齐视图

时间:2018-07-26 07:44:01

标签: android android-layout android-databinding

我可以将数据绑定与三元运算符结合使用来对齐视图。

android:layout_toLeftOf= 
"@{value.getUnit().equals(@string/mb)?@+id/lyt_value:@+id/lyt_value2}"

上面的代码给出了编译错误“ expr有望”

1 个答案:

答案 0 :(得分:0)

尝试一下:

attachmentToken: string;

public submitForm(finalData) {
  const { attachment, ...data } = finalData;
  return !this.attachmentToken ? this.attachmentCall(attachment, data) : this.formDataCall(finalData);
}

attachementCall(attachment, data) {
  this.http
    // at first get attachment's token
    .post('/attachments', attachment)
    .pipe(
      switchMap((attachmentToken) => {
        const formData = {
          data,
          attachment: attachmentToken
        };

        this.attachmentToken = attachmentToken;

        // submit form data
        return this.formDataCall(formData);
      }),
    );
}

formDataCall() {
  return this.http.post('/submitformdata', formData);
}