gpt4 book ai didi

ember.js - 如何在 Ember.js 中将内容与 JSON 绑定(bind)

转载 作者:行者123 更新时间:2023-12-04 17:03:14 24 4
gpt4 key购买 nike

所有示例都在 arraycontroller.content 中使用固定数据源,而我使用的是从另一个 Web 服务生成并返回 JSON 的动态数据源,它不会创建我在 Ember 中声明的对象,
这是代码示例:

        ET.AppYear = Ember.Object.extend({
text:null,
value:null
});
ET.EmailTypes = Ember.Object.extend();

ET.appYearController = Ember.ArrayController.create({
content: [],
loadYears: function (year) {
if (year != null) {
for (var i = -5; i < 5; i++) {
this.pushObject({ text: year + i, value: year + i });
//.AppYear.create({ text: year + i, value: year + i });
}
}
}
});

ET.selectedAppYearController = Ember.Object.create({
selectedAppYear: '2011',
alertChange: function(){
alert("selected App Year is now " + this.get('selectedAppYear'));
}.observes('selectedAppYear'),
isChanged: function () {
if (this.appYear != null) {
this.set('selection',this.get('content'));
//LoadETByAppYearETTypeID(this.selectedAppYear, ET.selectedEmailTypesController.emailType.email_template_type_id);
}
} .observes('selectedAppYear'),
AppYear: function() {
var ay = ET.appYearController.findProperty('text',this.get('selectedAppYear'));
return ay;
}.property('selectedAppYear')
});

如您所见,我将调用 ET.appYearController.loadYears (JSON) 在 AJAX 回传中,它将使用 this.pushObject 创建内容,但这不是 ET.AppYear对象模式,而我调用 ET.selectedAppYearController.selectedAppYear ,它返回一个 undefined object ,它实际上返回一个带有 {text:xx,value,xx} 的对象架构。这就是为什么 selectionBinding在这种情况下也不起作用。

那么将 JSON 元素作为已定义对象导入并放入内容的典型解决方案是什么?!

最佳答案

看看 Ember 数据库,它是为您的用例和相关用例制作的:

https://github.com/emberjs/data

关于ember.js - 如何在 Ember.js 中将内容与 JSON 绑定(bind),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9020614/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com