Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

请教下下面的需求如何实现比较好? #498

Open
acelan86 opened this issue Jul 11, 2015 · 4 comments
Open

请教下下面的需求如何实现比较好? #498

acelan86 opened this issue Jul 11, 2015 · 4 comments

Comments

@acelan86
Copy link

Model.js

var items = [
      {prop1: 'a', prop2: 'b'},
      {prop1: 'a', prop2: 'b'}
];

model.set('items', items);

Tpl

 <!-- for: ${items} as ${item} -->
<div data-ui-type="FooUI" data-ui-value="${item}"></div>
<!-- /for -->

这里假设FooUI是我自定义的一个ui组件,我希望通过items遍历出多个ui,但是这里${item}模板变量替换后是字符串的'[Object object]',导致FooUI的值是'[Object object]'而无法正常初始化

请教这里改如何设计FooUI或者如何书写模板?

@acelan86
Copy link
Author

@otakustay

@otakustay
Copy link
Member

试试这样,手头没环境,不确定是不是完全正确,理论上可行:

<!-- for: ${items} as ${item}, ${index} -->
    <div data-ui-type="FooUI" data-ui-value="@items.${index}"></div>
<!-- /for -->

@acelan86
Copy link
Author

居然可以。。

<!-- for: ${items} as ${item}, ${index} -->
    <div data-ui-type="FooUI" data-ui-value="@items[${index}]"></div>
<!-- /for -->

之前试过这样,从getProperty方法来看不行,忘了还有这样的写法。。正好getProperty里面当作字符串属性名来获取了

function getProperty(target, path) {
            ...
                value = value[path[i]];
            }

            return value;
        }

这是误打误撞还是原来已经考虑到了。。

@otakustay
Copy link
Member

做etpl和esui之初就讨论过.foo['foo']的总是,支持[]的形式要花额外的代码没有什么必要,所以只支持了用.访问,无论key是什么都可以

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants